MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / signIn

Function signIn

packages/auth-client/src/client/index.tsx:246–323  ·  view source on GitHub ↗
(
  provider?: LiteralUnion<
    P extends RedirectableProviderType
      ? P | BuiltInProviderType
      : BuiltInProviderType
  >,
  options?: SignInOptions,
  authorizationParams?: SignInAuthorizationParams
)

Source from the content-addressed store, hash-verified

244 *
245 */
246export async function signIn<
247 P extends RedirectableProviderType | undefined = undefined
248>(
249 provider?: LiteralUnion<
250 P extends RedirectableProviderType
251 ? P | BuiltInProviderType
252 : BuiltInProviderType
253 >,
254 options?: SignInOptions,
255 authorizationParams?: SignInAuthorizationParams
256): Promise<
257 P extends RedirectableProviderType ? SignInResponse | undefined : undefined
258> {
259 const { callbackUrl = window.location.href, redirect = true } = options || {};
260
261 const baseUrl = __LINEN_AUTH.basePath;
262 const providers = await getProviders();
263
264 if (!providers) {
265 window.location.href = `${baseUrl}/error`;
266 return;
267 }
268
269 if (!provider || !(provider in providers)) {
270 window.location.href = `${baseUrl}/signin?${new URLSearchParams({
271 callbackUrl,
272 })}`;
273 return;
274 }
275
276 const isCredentials = providers[provider].type === 'credentials';
277 const isEmail = providers[provider].type === 'email';
278 const isSupportingReturn = isCredentials || isEmail;
279
280 const signInUrl = `${baseUrl}/${
281 isCredentials ? 'callback' : 'signin'
282 }/${provider}`;
283
284 const _signInUrl = `${signInUrl}?${new URLSearchParams(authorizationParams)}`;
285
286 const res = await fetch(_signInUrl, {
287 method: 'post',
288 headers: {
289 'Content-Type': 'application/x-www-form-urlencoded',
290 },
291 // @ts-expect-error
292 body: new URLSearchParams({
293 ...options,
294 csrfToken: await getCsrfToken(),
295 callbackUrl,
296 json: true,
297 }),
298 });
299
300 const data = await res.json();
301
302 // TODO: Do not redirect for Credentials and Email providers by default in next major
303 if (redirect || !isSupportingReturn) {

Callers

nothing calls this directly

Calls 4

getProvidersFunction · 0.85
getCsrfTokenFunction · 0.85
reloadMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected