({
userOptions,
providerId,
action,
host,
cookies: reqCookies,
callbackUrl: reqCallbackUrl,
csrfToken: reqCsrfToken,
isPost,
}: InitParams)
| 28 | |
| 29 | /** Initialize all internal options and cookies. */ |
| 30 | export async function init({ |
| 31 | userOptions, |
| 32 | providerId, |
| 33 | action, |
| 34 | host, |
| 35 | cookies: reqCookies, |
| 36 | callbackUrl: reqCallbackUrl, |
| 37 | csrfToken: reqCsrfToken, |
| 38 | isPost, |
| 39 | }: InitParams): Promise<{ |
| 40 | options: InternalOptions |
| 41 | cookies: cookie.Cookie[] |
| 42 | }> { |
| 43 | const url = parseUrl(host) |
| 44 | |
| 45 | const secret = createSecret({ userOptions, url }) |
| 46 | |
| 47 | const { providers, provider } = parseProviders({ |
| 48 | providers: userOptions.providers, |
| 49 | url, |
| 50 | providerId, |
| 51 | }) |
| 52 | |
| 53 | const maxAge = 30 * 24 * 60 * 60 // Sessions expire after 30 days of being idle by default |
| 54 | |
| 55 | // User provided options are overriden by other options, |
| 56 | // except for the options with special handling above |
| 57 | const options: InternalOptions = { |
| 58 | debug: false, |
| 59 | pages: {}, |
| 60 | theme: { |
| 61 | colorScheme: "auto", |
| 62 | logo: "", |
| 63 | brandColor: "", |
| 64 | }, |
| 65 | // Custom options override defaults |
| 66 | ...userOptions, |
| 67 | // These computed settings can have values in userOptions but we override them |
| 68 | // and are request-specific. |
| 69 | url, |
| 70 | action, |
| 71 | provider, |
| 72 | cookies: { |
| 73 | ...cookie.defaultCookies( |
| 74 | userOptions.useSecureCookies ?? url.base.startsWith("https://") |
| 75 | ), |
| 76 | // Allow user cookie options to override any cookie settings above |
| 77 | ...userOptions.cookies, |
| 78 | }, |
| 79 | secret, |
| 80 | providers, |
| 81 | // Session options |
| 82 | session: { |
| 83 | // If no adapter specified, force use of JSON Web Tokens (stateless) |
| 84 | strategy: userOptions.adapter ? "database" : "jwt", |
| 85 | maxAge, |
| 86 | updateAge: 24 * 60 * 60, |
| 87 | ...userOptions.session, |
no test coverage detected
searching dependent graphs…