better-auth 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/client.js +1 -4
- package/dist/client.js.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/plugins.js +1 -4
- package/dist/plugins.js.map +1 -1
- package/dist/preact.js +1 -4
- package/dist/preact.js.map +1 -1
- package/dist/react.js +1 -4
- package/dist/react.js.map +1 -1
- package/dist/social.js +1 -4
- package/dist/social.js.map +1 -1
- package/dist/solid.js +1 -4
- package/dist/solid.js.map +1 -1
- package/dist/svelte.js +1 -4
- package/dist/svelte.js.map +1 -1
- package/dist/vue.js +1 -4
- package/dist/vue.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/index.ts","../src/adapters/schema.ts","../src/api/middlewares/csrf.ts","../src/crypto/index.ts","../src/api/call.ts","../src/api/routes/sign-in.ts","../src/social-providers/apple.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/social-providers/utils.ts","../src/social-providers/discord.ts","../src/social-providers/facebook.ts","../src/social-providers/github.ts","../src/social-providers/google.ts","../src/social-providers/spotify.ts","../src/social-providers/twitch.ts","../src/social-providers/twitter.ts","../src/types/provider.ts","../src/social-providers/index.ts","../src/utils/state.ts","../src/api/routes/session.ts","../src/api/routes/callback.ts","../src/client/client-utils.ts","../src/utils/id.ts","../src/api/routes/sign-out.ts","../src/api/routes/forget-password.ts","../src/api/routes/verify-email.ts","../src/api/routes/csrf.ts","../src/api/routes/ok.ts","../src/api/routes/sign-up.ts","../src/api/routes/error.ts","../src/adapters/kysely.ts","../src/adapters/get-tables.ts","../src/adapters/utils.ts","../src/adapters/internal-adapter.ts","../src/utils/date.ts","../src/db/field.ts","../src/utils/cookies.ts","../src/utils/logger.ts","../src/init.ts","../src/auth.ts"],"sourcesContent":["import { type Context, type Endpoint, createRouter } from \"better-call\";\nimport { parseAccount, parseSession, parseUser } from \"../adapters/schema\";\nimport type { AuthContext } from \"../init\";\nimport type { BetterAuthOptions, InferSession, InferUser } from \"../types\";\nimport type { Prettify } from \"../types/helper\";\nimport { csrfMiddleware } from \"./middlewares/csrf\";\nimport {\n\tcallbackOAuth,\n\tforgetPassword,\n\tgetSession,\n\tresetPassword,\n\tsendVerificationEmail,\n\tsignInEmail,\n\tsignInOAuth,\n\tsignOut,\n\tverifyEmail,\n} from \"./routes\";\nimport { getCSRFToken } from \"./routes/csrf\";\nimport { ok, welcome } from \"./routes/ok\";\nimport { signUpEmail } from \"./routes/sign-up\";\nimport { error } from \"./routes/error\";\n\nexport const router = <C extends AuthContext, Option extends BetterAuthOptions>(\n\tctx: C,\n) => {\n\tconst pluginEndpoints = ctx.options.plugins?.reduce(\n\t\t(acc, plugin) => {\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t...plugin.endpoints,\n\t\t\t};\n\t\t},\n\t\t{} as Record<string, any>,\n\t);\n\n\tconst middlewares =\n\t\tctx.options.plugins\n\t\t\t?.map((plugin) =>\n\t\t\t\tplugin.middlewares?.map((m) => {\n\t\t\t\t\tconst middleware = (async (context: any) => {\n\t\t\t\t\t\treturn m.middleware({\n\t\t\t\t\t\t\t...context,\n\t\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\t\t...ctx,\n\t\t\t\t\t\t\t\t...context.context,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}) as Endpoint;\n\t\t\t\t\tmiddleware.path = m.path;\n\t\t\t\t\tmiddleware.options = m.middleware.options;\n\t\t\t\t\tmiddleware.headers = m.middleware.headers;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpath: m.path,\n\t\t\t\t\t\tmiddleware,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.filter((plugin) => plugin !== undefined)\n\t\t\t.flat() || [];\n\n\tasync function typedSession(\n\t\tctx: Context<\n\t\t\t\"/session\",\n\t\t\t{\n\t\t\t\tmethod: \"GET\";\n\t\t\t\trequireHeaders: true;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tconst handler = await getSession(ctx);\n\t\treturn handler as {\n\t\t\tsession: Prettify<InferSession<Option>>;\n\t\t\tuser: Prettify<InferUser<Option>>;\n\t\t} | null;\n\t}\n\ttypedSession.path = getSession.path;\n\ttypedSession.method = getSession.method;\n\ttypedSession.options = getSession.options;\n\ttypedSession.headers = getSession.headers;\n\n\tconst baseEndpoints = {\n\t\tsignInOAuth,\n\t\tcallbackOAuth,\n\t\tgetCSRFToken,\n\t\tgetSession: typedSession,\n\t\tsignOut,\n\t\tsignUpEmail,\n\t\tsignInEmail,\n\t\tforgetPassword,\n\t\tresetPassword,\n\t\tverifyEmail,\n\t\tsendVerificationEmail,\n\t};\n\tconst endpoints = {\n\t\t...baseEndpoints,\n\t\t...pluginEndpoints,\n\t\tok,\n\t\twelcome,\n\t\terror,\n\t};\n\tlet api: Record<string, any> = {};\n\tfor (const [key, value] of Object.entries(endpoints)) {\n\t\tapi[key] = async (context: any) => {\n\t\t\tfor (const plugin of ctx.options.plugins || []) {\n\t\t\t\tif (plugin.hooks?.before) {\n\t\t\t\t\tfor (const hook of plugin.hooks.before) {\n\t\t\t\t\t\tconst match = hook.matcher({\n\t\t\t\t\t\t\t...context,\n\t\t\t\t\t\t\t...value,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (match) {\n\t\t\t\t\t\t\tconst hookRes = await hook.handler(context);\n\t\t\t\t\t\t\tif (hookRes && \"context\" in hookRes) {\n\t\t\t\t\t\t\t\tcontext = {\n\t\t\t\t\t\t\t\t\t...context,\n\t\t\t\t\t\t\t\t\t...hookRes.context,\n\t\t\t\t\t\t\t\t\t...value,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t//@ts-ignore\n\t\t\tconst endpointRes = value({\n\t\t\t\t...context,\n\t\t\t\tcontext: {\n\t\t\t\t\t...ctx,\n\t\t\t\t\t...context.context,\n\t\t\t\t},\n\t\t\t});\n\t\t\tlet response = endpointRes;\n\t\t\tfor (const plugin of ctx.options.plugins || []) {\n\t\t\t\tif (plugin.hooks?.after) {\n\t\t\t\t\tfor (const hook of plugin.hooks.after) {\n\t\t\t\t\t\tconst match = hook.matcher(context);\n\t\t\t\t\t\tif (match) {\n\t\t\t\t\t\t\tconst obj = Object.assign(context, {\n\t\t\t\t\t\t\t\treturned: endpointRes,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tconst hookRes = await hook.handler(obj);\n\t\t\t\t\t\t\tif (hookRes && \"response\" in hookRes) {\n\t\t\t\t\t\t\t\tresponse = hookRes.response as any;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn response;\n\t\t};\n\t\tapi[key].path = value.path;\n\t\tapi[key].method = value.method;\n\t\tapi[key].options = value.options;\n\t\tapi[key].headers = value.headers;\n\t}\n\treturn createRouter(api as typeof baseEndpoints, {\n\t\textraContext: ctx,\n\t\tbasePath: ctx.options.basePath,\n\t\trouterMiddleware: [\n\t\t\t{\n\t\t\t\tpath: \"/**\",\n\t\t\t\tmiddleware: csrfMiddleware,\n\t\t\t},\n\t\t\t...middlewares,\n\t\t],\n\t\t/**\n\t\t * this is to remove any sensitive data from the response\n\t\t */\n\t\tasync transformResponse(res) {\n\t\t\tlet body: Record<string, any> = {};\n\t\t\ttry {\n\t\t\t\tbody = await res.json();\n\t\t\t} catch (e) {\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\tif (body?.user) {\n\t\t\t\tbody.user = parseUser(ctx.options, body.user);\n\t\t\t}\n\t\t\tif (body?.session) {\n\t\t\t\tbody.session = parseSession(ctx.options, body.session);\n\t\t\t}\n\t\t\tif (body?.account) {\n\t\t\t\tbody.account = parseAccount(ctx.options, body.account);\n\t\t\t}\n\t\t\treturn new Response(body ? JSON.stringify(body) : null, {\n\t\t\t\theaders: res.headers,\n\t\t\t\tstatus: res.status,\n\t\t\t\tstatusText: res.statusText,\n\t\t\t});\n\t\t},\n\t\tonError(e) {\n\t\t\tconsole.log(e);\n\t\t},\n\t});\n};\n","import { z } from \"zod\";\nimport type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\n\nexport const accountSchema = z.object({\n\tid: z.string(),\n\tproviderId: z.string(),\n\taccountId: z.string(),\n\tuserId: z.string(),\n\taccessToken: z.string().nullable().optional(),\n\trefreshToken: z.string().nullable().optional(),\n\tidToken: z.string().nullable().optional(),\n\taccessTokenExpiresAt: z.date().nullable().optional(),\n\trefreshTokenExpiresAt: z.date().nullable().optional(),\n\t/**\n\t * Password is only stored in the credential provider\n\t */\n\tpassword: z.string().optional().nullable(),\n});\n\nexport const userSchema = z.object({\n\tid: z.string(),\n\temail: z.string().transform((val) => val.toLowerCase()),\n\temailVerified: z.boolean().default(false),\n\tname: z.string(),\n\timage: z.string().optional(),\n\tcreatedAt: z.date().default(new Date()),\n\tupdatedAt: z.date().default(new Date()),\n});\n\nexport const sessionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\texpiresAt: z.date(),\n\tipAddress: z.string().optional(),\n\tuserAgent: z.string().optional(),\n});\n\nexport type User = z.infer<typeof userSchema>;\nexport type Account = z.infer<typeof accountSchema>;\nexport type Session = z.infer<typeof sessionSchema>;\nexport interface MigrationTable {\n\tname: string;\n\ttimestamp: string;\n}\n\nexport function parseData<T extends Record<string, any>>(\n\tdata: T,\n\tschema: {\n\t\tfields: Record<string, FieldAttribute>;\n\t},\n) {\n\tconst fields = schema.fields;\n\tconst parsedData: Record<string, any> = {};\n\tfor (const key in data) {\n\t\tconst field = fields[key];\n\t\tif (!field) {\n\t\t\tparsedData[key] = data[key];\n\t\t\tcontinue;\n\t\t}\n\t\tif (field.returned === false) {\n\t\t\tcontinue;\n\t\t}\n\t\tparsedData[key] = data[key];\n\t}\n\treturn parsedData as T;\n}\n\nexport function getAllFields(options: BetterAuthOptions, table: string) {\n\tlet schema: Record<string, FieldAttribute> = {};\n\tfor (const plugin of options.plugins || []) {\n\t\tif (plugin.schema && plugin.schema[table]) {\n\t\t\tschema = {\n\t\t\t\t...schema,\n\t\t\t\t...plugin.schema[table].fields,\n\t\t\t};\n\t\t}\n\t}\n\treturn schema;\n}\n\nexport function parseUser(options: BetterAuthOptions, user: User) {\n\tconst schema = getAllFields(options, \"user\");\n\treturn parseData(user, { fields: schema });\n}\n\nexport function parseAccount(options: BetterAuthOptions, account: Account) {\n\tconst schema = getAllFields(options, \"account\");\n\treturn parseData(account, { fields: schema });\n}\n\nexport function parseSession(options: BetterAuthOptions, session: Session) {\n\tconst schema = getAllFields(options, \"session\");\n\treturn parseData(session, { fields: schema });\n}\n","import { APIError } from \"better-call\";\nimport { z } from \"zod\";\nimport { hs256 } from \"../../crypto\";\nimport { createAuthMiddleware } from \"../call\";\n\nexport const csrfMiddleware = createAuthMiddleware(\n\t{\n\t\tbody: z\n\t\t\t.object({\n\t\t\t\tcsrfToken: z.string().optional(),\n\t\t\t})\n\t\t\t.optional(),\n\t},\n\tasync (ctx) => {\n\t\tif (\n\t\t\tctx.request?.method !== \"POST\" ||\n\t\t\tctx.context.options.advanced?.disableCSRFCheck\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst url = new URL(ctx.request.url);\n\t\tconsole.log(url.origin, ctx.context.options.baseURL);\n\t\t/**\n\t\t * If origin is the same as baseURL or if the\n\t\t * origin is in the trustedOrigins then we\n\t\t * don't need to check the CSRF token.\n\t\t */\n\t\tif (\n\t\t\turl.origin === ctx.context.options.baseURL ||\n\t\t\tctx.context.options.trustedOrigins?.includes(url.origin)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst csrfToken = ctx.body?.csrfToken;\n\t\tconst csrfCookie = await ctx.getSignedCookie(\n\t\t\tctx.context.authCookies.csrfToken.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\tconst [token, hash] = csrfCookie?.split(\"!\") || [null, null];\n\t\tif (\n\t\t\t!csrfToken ||\n\t\t\t!csrfCookie ||\n\t\t\t!token ||\n\t\t\t!hash ||\n\t\t\tcsrfCookie !== csrfToken\n\t\t) {\n\t\t\tctx.setCookie(ctx.context.authCookies.csrfToken.name, \"\", {\n\t\t\t\tmaxAge: 0,\n\t\t\t});\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid CSRF Token\",\n\t\t\t});\n\t\t}\n\t\tconst expectedHash = await hs256(ctx.context.secret, token);\n\t\tif (hash !== expectedHash) {\n\t\t\tctx.setCookie(ctx.context.authCookies.csrfToken.name, \"\", {\n\t\t\t\tmaxAge: 0,\n\t\t\t});\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid CSRF Token\",\n\t\t\t});\n\t\t}\n\t},\n);\n","import { xchacha20poly1305 } from \"@noble/ciphers/chacha\";\nimport { bytesToHex, hexToBytes, utf8ToBytes } from \"@noble/ciphers/utils\";\nimport { managedNonce } from \"@noble/ciphers/webcrypto\";\nimport { sha256 } from \"@noble/hashes/sha256\";\n\nexport async function hs256(secretKey: string, message: string) {\n\tconst enc = new TextEncoder();\n\tconst algorithm = { name: \"HMAC\", hash: \"SHA-256\" };\n\tconst key = await crypto.subtle.importKey(\n\t\t\"raw\",\n\t\tenc.encode(secretKey),\n\t\talgorithm,\n\t\tfalse,\n\t\t[\"sign\", \"verify\"],\n\t);\n\tconst signature = await crypto.subtle.sign(\n\t\talgorithm.name,\n\t\tkey,\n\t\tenc.encode(message),\n\t);\n\treturn btoa(String.fromCharCode(...new Uint8Array(signature)));\n}\n\nexport type SymmetricEncryptOptions = {\n\tkey: string;\n\tdata: string;\n};\n\nexport const symmetricEncrypt = ({ key, data }: SymmetricEncryptOptions) => {\n\tconst keyAsBytes = sha256(key);\n\tconst dataAsBytes = utf8ToBytes(data);\n\tconst chacha = managedNonce(xchacha20poly1305)(keyAsBytes);\n\treturn bytesToHex(chacha.encrypt(dataAsBytes));\n};\n\nexport type SymmetricDecryptOptions = {\n\tkey: string;\n\tdata: string;\n};\n\nexport const symmetricDecrypt = ({ key, data }: SymmetricDecryptOptions) => {\n\tconst keyAsBytes = sha256(key);\n\tconst dataAsBytes = hexToBytes(data);\n\tconst chacha = managedNonce(xchacha20poly1305)(keyAsBytes);\n\treturn chacha.decrypt(dataAsBytes);\n};\n","import {\n\ttype Endpoint,\n\ttype EndpointResponse,\n\tcreateEndpointCreator,\n\tcreateMiddleware,\n\tcreateMiddlewareCreator,\n} from \"better-call\";\nimport type { AuthContext } from \"../init\";\nimport type { BetterAuthOptions } from \"../types/options\";\n\nexport const optionsMiddleware = createMiddleware(async () => {\n\t/**\n\t * This will be passed on the instance of\n\t * the context. Used to infer the type\n\t * here.\n\t */\n\treturn {} as AuthContext;\n});\n\nexport const createAuthMiddleware = createMiddlewareCreator({\n\tuse: [optionsMiddleware],\n});\n\nexport const createAuthEndpoint = createEndpointCreator({\n\tuse: [optionsMiddleware],\n});\n\nexport type AuthEndpoint = Endpoint<\n\t(ctx: {\n\t\toptions: BetterAuthOptions;\n\t\tbody: any;\n\t\tquery: any;\n\t\theaders: Headers;\n\t}) => Promise<EndpointResponse>\n>;\n\nexport type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;\n","import { APIError } from \"better-call\";\nimport { generateCodeVerifier } from \"oslo/oauth2\";\nimport { Argon2id } from \"oslo/password\";\nimport { z } from \"zod\";\nimport { oAuthProviderList } from \"../../social-providers\";\nimport { generateState } from \"../../utils/state\";\nimport { createAuthEndpoint } from \"../call\";\nimport { getSessionFromCtx } from \"./session\";\n\nexport const signInOAuth = createAuthEndpoint(\n\t\"/sign-in/social\",\n\t{\n\t\tmethod: \"POST\",\n\t\trequireHeaders: true,\n\t\tquery: z\n\t\t\t.object({\n\t\t\t\t/**\n\t\t\t\t * Redirect to the current URL after the\n\t\t\t\t * user has signed in.\n\t\t\t\t */\n\t\t\t\tcurrentURL: z.string().optional(),\n\t\t\t})\n\t\t\t.optional(),\n\t\tbody: z.object({\n\t\t\t/**\n\t\t\t * Callback URL to redirect to after the user has signed in.\n\t\t\t */\n\t\t\tcallbackURL: z.string().optional(),\n\t\t\t/**\n\t\t\t * OAuth2 provider to use`\n\t\t\t */\n\t\t\tprovider: z.enum(oAuthProviderList),\n\t\t}),\n\t},\n\tasync (c) => {\n\t\tconst provider = c.context.options.socialProvider?.find(\n\t\t\t(p) => p.id === c.body.provider,\n\t\t);\n\t\tif (!provider) {\n\t\t\tc.context.logger.error(\n\t\t\t\t\"Provider not found. Make sure to add the provider to your auth config\",\n\t\t\t\t{\n\t\t\t\t\tprovider: c.body.provider,\n\t\t\t\t},\n\t\t\t);\n\t\t\tthrow new APIError(\"NOT_FOUND\");\n\t\t}\n\t\tconst cookie = c.context.authCookies;\n\t\tconst currentURL = c.query?.currentURL\n\t\t\t? new URL(c.query?.currentURL)\n\t\t\t: null;\n\t\tconst state = generateState(\n\t\t\tc.body.callbackURL || currentURL?.origin || c.context.baseURL,\n\t\t\tc.query?.currentURL,\n\t\t);\n\t\ttry {\n\t\t\tawait c.setSignedCookie(\n\t\t\t\tcookie.state.name,\n\t\t\t\tstate.code,\n\t\t\t\tc.context.secret,\n\t\t\t\tcookie.state.options,\n\t\t\t);\n\t\t\tconst codeVerifier = generateCodeVerifier();\n\t\t\tawait c.setSignedCookie(\n\t\t\t\tcookie.pkCodeVerifier.name,\n\t\t\t\tcodeVerifier,\n\t\t\t\tc.context.secret,\n\t\t\t\tcookie.pkCodeVerifier.options,\n\t\t\t);\n\t\t\tconst url = provider.createAuthorizationURL({\n\t\t\t\tstate: state.state,\n\t\t\t\tcodeVerifier,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\turl: url.toString(),\n\t\t\t\tstate: state.state,\n\t\t\t\tcodeVerifier,\n\t\t\t\tredirect: true,\n\t\t\t};\n\t\t} catch (e) {\n\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\");\n\t\t}\n\t},\n);\n\nexport const signInEmail = createAuthEndpoint(\n\t\"/sign-in/email\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\temail: z.string().email(),\n\t\t\tpassword: z.string(),\n\t\t\tcallbackURL: z.string().optional(),\n\t\t\t/**\n\t\t\t * If this is true the session will only be valid for the current browser session\n\t\t\t * @default false\n\t\t\t */\n\t\t\tdontRememberMe: z.boolean().default(false).optional(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tif (!ctx.context.options?.emailAndPassword?.enabled) {\n\t\t\tctx.context.logger.error(\"Email and password is not enabled\");\n\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\tmessage: \"Email and password is not enabled\",\n\t\t\t});\n\t\t}\n\t\tconst currentSession = await getSessionFromCtx(ctx);\n\t\tif (currentSession) {\n\t\t\treturn ctx.json({\n\t\t\t\tuser: currentSession.user,\n\t\t\t\tsession: currentSession.session,\n\t\t\t\tredirect: !!ctx.body.callbackURL,\n\t\t\t\turl: ctx.body.callbackURL,\n\t\t\t});\n\t\t}\n\t\tconst { email, password } = ctx.body;\n\t\tconst argon2id = new Argon2id();\n\t\tconst user = await ctx.context.internalAdapter.findUserByEmail(email);\n\t\tif (!user) {\n\t\t\tawait argon2id.hash(password);\n\t\t\tctx.context.logger.error(\"User not found\", { email });\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid email or password\",\n\t\t\t});\n\t\t}\n\t\tconst credentialAccount = user.accounts.find(\n\t\t\t(a) => a.providerId === \"credential\",\n\t\t);\n\t\tif (!credentialAccount) {\n\t\t\tctx.context.logger.error(\"Credential account not found\", { email });\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid email or password\",\n\t\t\t});\n\t\t}\n\t\tconst currentPassword = credentialAccount?.password;\n\t\tif (!currentPassword) {\n\t\t\tctx.context.logger.error(\"Password not found\", { email });\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Unexpected error\",\n\t\t\t});\n\t\t}\n\t\tconst validPassword = await argon2id.verify(currentPassword, password);\n\t\tif (!validPassword) {\n\t\t\tctx.context.logger.error(\"Invalid password\");\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid email or password\",\n\t\t\t});\n\t\t}\n\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\tuser.user.id,\n\t\t\tctx.request,\n\t\t);\n\t\tawait ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tsession.id,\n\t\t\tctx.context.secret,\n\t\t\tctx.body.dontRememberMe\n\t\t\t\t? {\n\t\t\t\t\t\t...ctx.context.authCookies.sessionToken.options,\n\t\t\t\t\t\tmaxAge: undefined,\n\t\t\t\t\t}\n\t\t\t\t: ctx.context.authCookies.sessionToken.options,\n\t\t);\n\t\treturn ctx.json({\n\t\t\tuser: user.user,\n\t\t\tsession,\n\t\t\tredirect: !!ctx.body.callbackURL,\n\t\t\turl: ctx.body.callbackURL,\n\t\t});\n\t},\n);\n","import { OAuth2Tokens } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { parseJWT } from \"oslo/jwt\";\nimport { betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\nimport { getRedirectURI } from \"./utils\";\nexport interface AppleProfile {\n\t/**\n\t * The subject registered claim identifies the principal that’s the subject\n\t * of the identity token. Because this token is for your app, the value is\n\t * the unique identifier for the user.\n\t */\n\tsub: string;\n\t/**\n\t * A String value representing the user's email address.\n\t * The email address is either the user's real email address or the proxy\n\t * address, depending on their status private email relay service.\n\t */\n\temail: string;\n\t/**\n\t * A string or Boolean value that indicates whether the service verifies\n\t * the email. The value can either be a string (\"true\" or \"false\") or a\n\t * Boolean (true or false). The system may not verify email addresses for\n\t * Sign in with Apple at Work & School users, and this claim is \"false\" or\n\t * false for those users.\n\t */\n\temail_verified: true | \"true\";\n\t/**\n\t * A string or Boolean value that indicates whether the email that the user\n\t * shares is the proxy address. The value can either be a string (\"true\" or\n\t * \"false\") or a Boolean (true or false).\n\t */\n\tis_private_email: boolean;\n\t/**\n\t * An Integer value that indicates whether the user appears to be a real\n\t * person. Use the value of this claim to mitigate fraud. The possible\n\t * values are: 0 (or Unsupported), 1 (or Unknown), 2 (or LikelyReal). For\n\t * more information, see ASUserDetectionStatus. This claim is present only\n\t * in iOS 14 and later, macOS 11 and later, watchOS 7 and later, tvOS 14\n\t * and later. The claim isn’t present or supported for web-based apps.\n\t */\n\treal_user_status: number;\n\t/**\n\t * The user’s full name in the format provided during the authorization\n\t * process.\n\t */\n\tname: string;\n}\n\nexport interface AppleOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const apple = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: AppleOptions) => {\n\tconst tokenEndpoint = \"https://appleid.apple.com/auth/token\";\n\tredirectURI = getRedirectURI(\"apple\", redirectURI);\n\treturn {\n\t\tid: \"apple\",\n\t\tname: \"Apple\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scope = scopes || [\"email\", \"name\", \"openid\"];\n\t\t\treturn new URL(\n\t\t\t\t`https://appleid.apple.com/auth/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectURI}&scope=${_scope.join(\n\t\t\t\t\t\" \",\n\t\t\t\t)}&state=${state}`,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code) => {\n\t\t\tconst data = await betterFetch<OAuth2Tokens>(tokenEndpoint, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: new URLSearchParams({\n\t\t\t\t\tclient_id: clientId,\n\t\t\t\t\tclient_secret: clientSecret,\n\t\t\t\t\tgrant_type: \"authorization_code\",\n\t\t\t\t\tcode,\n\t\t\t\t}),\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (data.error) {\n\t\t\t\tthrow new BetterAuthError(data.error?.message || \"\");\n\t\t\t}\n\t\t\treturn data.data;\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tconst data = parseJWT(token.idToken())?.payload as AppleProfile | null;\n\t\t\tif (!data) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: data.sub,\n\t\t\t\t\tname: data.name,\n\t\t\t\t\temail: data.email,\n\t\t\t\t\temailVerified: data.email_verified === \"true\",\n\t\t\t\t},\n\t\t\t\tdata,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<AppleProfile>;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\t//@ts-ignore\n\tconst env: any =\n\t\ttypeof process !== \"undefined\"\n\t\t\t? process.env\n\t\t\t: typeof import.meta !== \"undefined\"\n\t\t\t\t? //@ts-ignore\n\t\t\t\t\timport.meta.env\n\t\t\t\t: {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { getBaseURL } from \"../utils/base-url\";\n\nexport function getRedirectURI(providerId: string, redirectURI?: string) {\n\treturn redirectURI || `${getBaseURL()}/api/auth/callback/${providerId}`;\n}\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Discord } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface DiscordProfile extends Record<string, any> {\n\t/** the user's id (i.e. the numerical snowflake) */\n\tid: string;\n\t/** the user's username, not unique across the platform */\n\tusername: string;\n\t/** the user's Discord-tag */\n\tdiscriminator: string;\n\t/** the user's display name, if it is set */\n\tglobal_name: string | null;\n\t/**\n\t * the user's avatar hash:\n\t * https://discord.com/developers/docs/reference#image-formatting\n\t */\n\tavatar: string | null;\n\t/** whether the user belongs to an OAuth2 application */\n\tbot?: boolean;\n\t/**\n\t * whether the user is an Official Discord System user (part of the urgent\n\t * message system)\n\t */\n\tsystem?: boolean;\n\t/** whether the user has two factor enabled on their account */\n\tmfa_enabled: boolean;\n\t/**\n\t * the user's banner hash:\n\t * https://discord.com/developers/docs/reference#image-formatting\n\t */\n\tbanner: string | null;\n\n\t/** the user's banner color encoded as an integer representation of hexadecimal color code */\n\taccent_color: number | null;\n\n\t/**\n\t * the user's chosen language option:\n\t * https://discord.com/developers/docs/reference#locales\n\t */\n\tlocale: string;\n\t/** whether the email on this account has been verified */\n\tverified: boolean;\n\t/** the user's email */\n\temail: string;\n\t/**\n\t * the flags on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-user-flags\n\t */\n\tflags: number;\n\t/**\n\t * the type of Nitro subscription on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-premium-types\n\t */\n\tpremium_type: number;\n\t/**\n\t * the public flags on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-user-flags\n\t */\n\tpublic_flags: number;\n\t/** undocumented field; corresponds to the user's custom nickname */\n\tdisplay_name: string | null;\n\t/**\n\t * undocumented field; corresponds to the Discord feature where you can e.g.\n\t * put your avatar inside of an ice cube\n\t */\n\tavatar_decoration: string | null;\n\t/**\n\t * undocumented field; corresponds to the premium feature where you can\n\t * select a custom banner color\n\t */\n\tbanner_color: string | null;\n\t/** undocumented field; the CDN URL of their profile picture */\n\timage_url: string;\n}\n\nexport interface DiscordOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const discord = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: DiscordOptions) => {\n\tconst discordArctic = new Discord(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"discord\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"discord\",\n\t\tname: \"Discord\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scope = scopes || [\"email\"];\n\t\t\treturn discordArctic.createAuthorizationURL(state, _scope);\n\t\t},\n\t\tvalidateAuthorizationCode: discordArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<DiscordProfile>(\n\t\t\t\t\"https://discord.com/api/users/@me\",\n\t\t\t\t{\n\t\t\t\t\tauth: {\n\t\t\t\t\t\ttype: \"Bearer\",\n\t\t\t\t\t\ttoken: token.accessToken,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.display_name || profile.username || \"\",\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\temailVerified: profile.verified,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<DiscordProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Facebook } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface FacebookProfile {\n\tid: string;\n\tname: string;\n\temail: string;\n\temail_verified: boolean;\n\tpicture: {\n\t\tdata: {\n\t\t\theight: number;\n\t\t\tis_silhouette: boolean;\n\t\t\turl: string;\n\t\t\twidth: number;\n\t\t};\n\t};\n}\nexport interface FacebookOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\nexport const facebook = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: FacebookOptions) => {\n\tconst facebookArctic = new Facebook(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"facebook\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"facebook\",\n\t\tname: \"Facebook\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"email\", \"public_profile\"];\n\t\t\treturn facebookArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: facebookArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<FacebookProfile>(\n\t\t\t\t\"https://graph.facebook.com/me\",\n\t\t\t\t{\n\t\t\t\t\tauth: {\n\t\t\t\t\t\ttype: \"Bearer\",\n\t\t\t\t\t\ttoken: token.accessToken,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\temailVerified: profile.email_verified,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<FacebookProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { GitHub } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface GithubProfile {\n\tlogin: string;\n\tid: string;\n\tnode_id: string;\n\tavatar_url: string;\n\tgravatar_id: string;\n\turl: string;\n\thtml_url: string;\n\tfollowers_url: string;\n\tfollowing_url: string;\n\tgists_url: string;\n\tstarred_url: string;\n\tsubscriptions_url: string;\n\torganizations_url: string;\n\trepos_url: string;\n\tevents_url: string;\n\treceived_events_url: string;\n\ttype: string;\n\tsite_admin: boolean;\n\tname: string;\n\tcompany: string;\n\tblog: string;\n\tlocation: string;\n\temail: string;\n\thireable: boolean;\n\tbio: string;\n\ttwitter_username: string;\n\tpublic_repos: string;\n\tpublic_gists: string;\n\tfollowers: string;\n\tfollowing: string;\n\tcreated_at: string;\n\tupdated_at: string;\n\tprivate_gists: string;\n\ttotal_private_repos: string;\n\towned_private_repos: string;\n\tdisk_usage: string;\n\tcollaborators: string;\n\ttwo_factor_authentication: boolean;\n\tplan: {\n\t\tname: string;\n\t\tspace: string;\n\t\tprivate_repos: string;\n\t\tcollaborators: string;\n\t};\n\tfirst_name: string;\n\tlast_name: string;\n}\n\nexport interface GithubOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\nexport const github = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: GithubOptions) => {\n\tconst githubArctic = new GitHub(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"github\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"github\",\n\t\tname: \"Github\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"user:email\"];\n\t\t\treturn githubArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: githubArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<GithubProfile>(\n\t\t\t\t\"https://api.github.com/user\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tlet emailVerified = false;\n\t\t\tif (!profile.email) {\n\t\t\t\tconst { data, error } = await betterFetch<\n\t\t\t\t\t{\n\t\t\t\t\t\temail: string;\n\t\t\t\t\t\tprimary: boolean;\n\t\t\t\t\t\tverified: boolean;\n\t\t\t\t\t\tvisibility: \"public\" | \"private\";\n\t\t\t\t\t}[]\n\t\t\t\t>(\"https://api.github.com/user/emails\", {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t\t\"User-Agent\": \"better-auth\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (!error) {\n\t\t\t\t\tprofile.email = (data.find((e) => e.primary) ?? data[0])\n\t\t\t\t\t\t?.email as string;\n\t\t\t\t\temailVerified =\n\t\t\t\t\t\tdata.find((e) => e.email === profile.email)?.verified ?? false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.avatar_url,\n\t\t\t\t\temailVerified,\n\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<GithubProfile>;\n};\n","import { Google } from \"arctic\";\nimport { parseJWT } from \"oslo/jwt\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport interface GoogleProfile {\n\taud: string;\n\tazp: string;\n\temail: string;\n\temail_verified: boolean;\n\texp: number;\n\t/**\n\t * The family name of the user, or last name in most\n\t * Western languages.\n\t */\n\tfamily_name: string;\n\t/**\n\t * The given name of the user, or first name in most\n\t * Western languages.\n\t */\n\tgiven_name: string;\n\thd?: string;\n\tiat: number;\n\tiss: string;\n\tjti?: string;\n\tlocale?: string;\n\tname: string;\n\tnbf?: number;\n\tpicture: string;\n\tsub: string;\n}\n\nexport interface GoogleOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const google = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: GoogleOptions) => {\n\tconst googleArctic = new Google(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"google\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"google\",\n\t\tname: \"Google\",\n\t\tcreateAuthorizationURL({ state, scopes, codeVerifier }) {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Google\");\n\t\t\t}\n\t\t\tconst _scopes = scopes || [\"email\", \"profile\"];\n\t\t\treturn googleArctic.createAuthorizationURL(state, codeVerifier, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code, codeVerifier) => {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Google\");\n\t\t\t}\n\t\t\treturn googleArctic.validateAuthorizationCode(code, codeVerifier);\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tif (!token.idToken) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst user = parseJWT(token.idToken())?.payload as GoogleProfile;\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: user.sub,\n\t\t\t\t\tname: user.name,\n\t\t\t\t\temail: user.email,\n\t\t\t\t\timage: user.picture,\n\t\t\t\t\temailVerified: user.email_verified,\n\t\t\t\t},\n\t\t\t\tdata: user,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<GoogleProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Spotify } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface SpotifyProfile {\n\tid: string;\n\tdisplay_name: string;\n\temail: string;\n\timages: {\n\t\turl: string;\n\t}[];\n}\n\nexport interface SpotifyOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const spotify = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: SpotifyOptions) => {\n\tconst spotifyArctic = new Spotify(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"spotify\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"spotify\",\n\t\tname: \"Spotify\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"user-read-email\"];\n\t\t\treturn spotifyArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: spotifyArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<SpotifyProfile>(\n\t\t\t\t\"https://api.spotify.com/v1/me\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.display_name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.images[0]?.url,\n\t\t\t\t\temailVerified: false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<SpotifyProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Twitch } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface TwitchProfile {\n\t/**\n\t * The sub of the user\n\t */\n\tsub: string;\n\t/**\n\t * The preferred username of the user\n\t */\n\tpreferred_username: string;\n\t/**\n\t * The email of the user\n\t */\n\temail: string;\n\t/**\n\t * The picture of the user\n\t */\n\tpicture: string;\n}\n\nexport interface TwitchOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const twitch = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: TwitchOptions) => {\n\tconst twitchArctic = new Twitch(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"twitch\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"twitch\",\n\t\tname: \"Twitch\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"activity:write\", \"read\"];\n\t\t\treturn twitchArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: twitchArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<TwitchProfile>(\n\t\t\t\t\"https://api.twitch.tv/helix/users\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.sub,\n\t\t\t\t\tname: profile.preferred_username,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.picture,\n\t\t\t\t\temailVerified: false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<TwitchProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Twitter } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport interface TwitterProfile {\n\tdata: {\n\t\t/**\n\t\t * Unique identifier of this user. This is returned as a string in order to avoid complications with languages and tools\n\t\t * that cannot handle large integers.\n\t\t */\n\t\tid: string;\n\t\t/** The friendly name of this user, as shown on their profile. */\n\t\tname: string;\n\t\t/** @note Email is currently unsupported by Twitter. */\n\t\temail?: string;\n\t\t/** The Twitter handle (screen name) of this user. */\n\t\tusername: string;\n\t\t/**\n\t\t * The location specified in the user's profile, if the user provided one.\n\t\t * As this is a freeform value, it may not indicate a valid location, but it may be fuzzily evaluated when performing searches with location queries.\n\t\t *\n\t\t * To return this field, add `user.fields=location` in the authorization request's query parameter.\n\t\t */\n\t\tlocation?: string;\n\t\t/**\n\t\t * This object and its children fields contain details about text that has a special meaning in the user's description.\n\t\t *\n\t\t *To return this field, add `user.fields=entities` in the authorization request's query parameter.\n\t\t */\n\t\tentities?: {\n\t\t\t/** Contains details about the user's profile website. */\n\t\t\turl: {\n\t\t\t\t/** Contains details about the user's profile website. */\n\t\t\t\turls: Array<{\n\t\t\t\t\t/** The start position (zero-based) of the recognized user's profile website. All start indices are inclusive. */\n\t\t\t\t\tstart: number;\n\t\t\t\t\t/** The end position (zero-based) of the recognized user's profile website. This end index is exclusive. */\n\t\t\t\t\tend: number;\n\t\t\t\t\t/** The URL in the format entered by the user. */\n\t\t\t\t\turl: string;\n\t\t\t\t\t/** The fully resolved URL. */\n\t\t\t\t\texpanded_url: string;\n\t\t\t\t\t/** The URL as displayed in the user's profile. */\n\t\t\t\t\tdisplay_url: string;\n\t\t\t\t}>;\n\t\t\t};\n\t\t\t/** Contains details about URLs, Hashtags, Cashtags, or mentions located within a user's description. */\n\t\t\tdescription: {\n\t\t\t\thashtags: Array<{\n\t\t\t\t\tstart: number;\n\t\t\t\t\tend: number;\n\t\t\t\t\ttag: string;\n\t\t\t\t}>;\n\t\t\t};\n\t\t};\n\t\t/**\n\t\t * Indicate if this user is a verified Twitter user.\n\t\t *\n\t\t * To return this field, add `user.fields=verified` in the authorization request's query parameter.\n\t\t */\n\t\tverified?: boolean;\n\t\t/**\n\t\t * The text of this user's profile description (also known as bio), if the user provided one.\n\t\t *\n\t\t * To return this field, add `user.fields=description` in the authorization request's query parameter.\n\t\t */\n\t\tdescription?: string;\n\t\t/**\n\t\t * The URL specified in the user's profile, if present.\n\t\t *\n\t\t * To return this field, add `user.fields=url` in the authorization request's query parameter.\n\t\t */\n\t\turl?: string;\n\t\t/** The URL to the profile image for this user, as shown on the user's profile. */\n\t\tprofile_image_url?: string;\n\t\tprotected?: boolean;\n\t\t/**\n\t\t * Unique identifier of this user's pinned Tweet.\n\t\t *\n\t\t * You can obtain the expanded object in `includes.tweets` by adding `expansions=pinned_tweet_id` in the authorization request's query parameter.\n\t\t */\n\t\tpinned_tweet_id?: string;\n\t\tcreated_at?: string;\n\t};\n\tincludes?: {\n\t\ttweets?: Array<{\n\t\t\tid: string;\n\t\t\ttext: string;\n\t\t}>;\n\t};\n\t[claims: string]: unknown;\n}\n\nexport interface TwitterOption {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const twitter = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: TwitterOption) => {\n\tconst twitterArctic = new Twitter(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"twitter\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"twitter\",\n\t\tname: \"Twitter\",\n\t\tcreateAuthorizationURL(data) {\n\t\t\tconst _scopes = data.scopes || [\"account_info.read\"];\n\t\t\treturn twitterArctic.createAuthorizationURL(\n\t\t\t\tdata.state,\n\t\t\t\tdata.codeVerifier,\n\t\t\t\t_scopes,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code, codeVerifier) => {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Twitter\");\n\t\t\t}\n\t\t\treturn twitterArctic.validateAuthorizationCode(code, codeVerifier);\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<TwitterProfile>(\n\t\t\t\t\"https://api.x.com/2/users/me?user.fields=profile_image_url\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (!profile.data.email) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.data.id,\n\t\t\t\t\tname: profile.data.name,\n\t\t\t\t\temail: profile.data.email,\n\t\t\t\t\timage: profile.data.profile_image_url,\n\t\t\t\t\temailVerified: profile.data.verified || false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<TwitterProfile>;\n};\n","import type { User } from \"../adapters/schema\";\nimport type { oAuthProviderList } from \"../social-providers\";\nimport type { LiteralString } from \"./helper\";\nimport { OAuth2Tokens } from \"arctic\";\n\nexport interface OAuthProvider<\n\tT extends Record<string, any> = Record<string, any>,\n> {\n\tid: LiteralString;\n\tcreateAuthorizationURL: (data: {\n\t\tstate: string;\n\t\tcodeVerifier: string;\n\t\tscopes?: string[];\n\t}) => URL;\n\tname: string;\n\tvalidateAuthorizationCode: (\n\t\tcode: string,\n\t\tcodeVerifier?: string,\n\t) => Promise<OAuth2Tokens>;\n\tgetUserInfo: (token: OAuth2Tokens) => Promise<{\n\t\tuser: Omit<User, \"createdAt\" | \"updatedAt\">;\n\t\tdata: T;\n\t} | null>;\n\trefreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;\n\trevokeToken?: (token: string) => Promise<void>;\n}\n\nexport type OAuthProviderList = typeof oAuthProviderList;\n","import { apple } from \"./apple\";\nimport { discord } from \"./discord\";\nimport { facebook } from \"./facebook\";\nimport { github } from \"./github\";\nimport { google } from \"./google\";\nimport { spotify } from \"./spotify\";\nimport { twitch } from \"./twitch\";\nimport { twitter } from \"./twitter\";\n\nexport const oAuthProviders = {\n\tapple,\n\tdiscord,\n\tfacebook,\n\tgithub,\n\tgoogle,\n\tspotify,\n\ttwitch,\n\ttwitter,\n};\n\nexport const oAuthProviderList = Object.keys(oAuthProviders) as [\n\t\"github\",\n\t...(keyof typeof oAuthProviders)[],\n];\n\nexport * from \"./github\";\nexport * from \"./google\";\nexport * from \"./apple\";\nexport * from \"./discord\";\nexport * from \"./spotify\";\nexport * from \"./twitch\";\nexport * from \"./facebook\";\nexport * from \"./twitter\";\nexport * from \"../types/provider\";\n","import { generateState as generateStateOAuth } from \"oslo/oauth2\";\n\nexport function generateState(callbackURL?: string, currentURL?: string) {\n\tconst code = generateStateOAuth();\n\tconst state = `${code}!${callbackURL}!${currentURL}`;\n\treturn { state, code };\n}\n\nexport function parseState(state: string) {\n\tconst [code, callbackURL, currentURL] = state.split(\"!\");\n\treturn { code, callbackURL, currentURL };\n}\n","import type { Context } from \"better-call\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const getSession = createAuthEndpoint(\n\t\"/session\",\n\t{\n\t\tmethod: \"GET\",\n\t\trequireHeaders: true,\n\t},\n\tasync (ctx) => {\n\t\tconst sessionCookieToken = await ctx.getSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\tif (!sessionCookieToken) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 401,\n\t\t\t});\n\t\t}\n\t\tconst session =\n\t\t\tawait ctx.context.internalAdapter.findSession(sessionCookieToken);\n\t\tif (!session || session.session.expiresAt < new Date()) {\n\t\t\tctx.setSignedCookie(\n\t\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\t\t\"\",\n\t\t\t\tctx.context.secret,\n\t\t\t\t{\n\t\t\t\t\tmaxAge: 0,\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 401,\n\t\t\t});\n\t\t}\n\t\tconst updatedSession = await ctx.context.internalAdapter.updateSession(\n\t\t\tsession.session,\n\t\t);\n\n\t\tawait ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tupdatedSession.id,\n\t\t\tctx.context.secret,\n\t\t\t{\n\t\t\t\t...ctx.context.authCookies.sessionToken.options,\n\t\t\t\tmaxAge: updatedSession.expiresAt.valueOf() - Date.now(),\n\t\t\t},\n\t\t);\n\t\treturn ctx.json({\n\t\t\tsession: updatedSession,\n\t\t\tuser: session.user,\n\t\t});\n\t},\n);\n\nexport const getSessionFromCtx = async (ctx: Context<any, any>) => {\n\tconst session = await getSession({\n\t\t...ctx,\n\t\t//@ts-expect-error: By default since this request context comes from a router it'll have a `router` flag which force it to be a request object\n\t\t_flag: undefined,\n\t});\n\treturn session;\n};\n","import { APIError } from \"better-call\";\nimport { z } from \"zod\";\nimport { userSchema } from \"../../adapters/schema\";\nimport { HIDE_ON_CLIENT_METADATA } from \"../../client/client-utils\";\nimport { generateId } from \"../../utils/id\";\nimport { parseState } from \"../../utils/state\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const callbackOAuth = createAuthEndpoint(\n\t\"/callback/:id\",\n\t{\n\t\tmethod: \"GET\",\n\t\tquery: z.object({\n\t\t\tstate: z.string(),\n\t\t\tcode: z.string(),\n\t\t\tcode_verifier: z.string().optional(),\n\t\t}),\n\t\tmetadata: HIDE_ON_CLIENT_METADATA,\n\t},\n\tasync (c) => {\n\t\tconst provider = c.context.options.socialProvider?.find(\n\t\t\t(p) => p.id === c.params.id,\n\t\t);\n\t\tif (!provider) {\n\t\t\tc.context.logger.error(\n\t\t\t\t\"Oauth provider with id\",\n\t\t\t\tc.params.id,\n\t\t\t\t\"not found\",\n\t\t\t);\n\t\t\tthrow new APIError(\"NOT_FOUND\");\n\t\t}\n\t\tconst tokens = await provider.validateAuthorizationCode(\n\t\t\tc.query.code,\n\t\t\tc.query.code_verifier || \"\",\n\t\t);\n\t\tif (!tokens) {\n\t\t\tc.context.logger.error(\"Code verification failed\");\n\t\t\tthrow new APIError(\"UNAUTHORIZED\");\n\t\t}\n\t\tconst user = await provider.getUserInfo(tokens).then((res) => res?.user);\n\t\tconst id = generateId();\n\t\tconst data = userSchema.safeParse({\n\t\t\t...user,\n\t\t\tid,\n\t\t});\n\t\tconst { callbackURL, currentURL } = parseState(c.query.state);\n\t\tif (!user || data.success === false) {\n\t\t\tif (currentURL) {\n\t\t\t\tthrow c.redirect(`${currentURL}?error=oauth_validation_failed`);\n\t\t\t} else {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\");\n\t\t\t}\n\t\t}\n\t\tif (!callbackURL) {\n\t\t\tc.context.logger.error(\"Callback URL not found\");\n\t\t\tthrow new APIError(\"FORBIDDEN\");\n\t\t}\n\t\t//find user in db\n\t\tconst dbUser = await c.context.internalAdapter.findUserByEmail(user.email);\n\t\tconst userId = dbUser?.user.id;\n\t\tif (dbUser) {\n\t\t\t//check if user has already linked this provider\n\t\t\tconst hasBeenLinked = dbUser.accounts.find(\n\t\t\t\t(a) => a.providerId === provider.id,\n\t\t\t);\n\t\t\tif (!hasBeenLinked && !user.emailVerified) {\n\t\t\t\tc.context.logger.error(\"User already exists\");\n\t\t\t\tconst url = new URL(currentURL || callbackURL);\n\t\t\t\turl.searchParams.set(\"error\", \"user_already_exists\");\n\t\t\t\tthrow c.redirect(url.toString());\n\t\t\t}\n\n\t\t\tif (!hasBeenLinked && user.emailVerified) {\n\t\t\t\tawait c.context.internalAdapter.linkAccount({\n\t\t\t\t\tproviderId: provider.id,\n\t\t\t\t\taccountId: user.id,\n\t\t\t\t\tid: `${provider.id}:${user.id}`,\n\t\t\t\t\tuserId: dbUser.user.id,\n\t\t\t\t\t...tokens,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tawait c.context.internalAdapter.createOAuthUser(data.data, {\n\t\t\t\t\t...tokens,\n\t\t\t\t\tid: `${provider.id}:${user.id}`,\n\t\t\t\t\tproviderId: provider.id,\n\t\t\t\t\taccountId: user.id,\n\t\t\t\t\tuserId: id,\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\tconst url = new URL(currentURL || callbackURL);\n\t\t\t\turl.searchParams.set(\"error\", \"unable_to_create_user\");\n\t\t\t\tc.setHeader(\"Location\", url.toString());\n\t\t\t\tthrow c.redirect(url.toString());\n\t\t\t}\n\t\t}\n\t\t//this should never happen\n\t\tif (!userId && !id)\n\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\tmessage: \"Unable to create user\",\n\t\t\t});\n\t\t//create session\n\t\tconst session = await c.context.internalAdapter.createSession(\n\t\t\tuserId || id,\n\t\t\tc.request,\n\t\t);\n\t\ttry {\n\t\t\tawait c.setSignedCookie(\n\t\t\t\tc.context.authCookies.sessionToken.name,\n\t\t\t\tsession.id,\n\t\t\t\tc.context.secret,\n\t\t\t\tc.context.authCookies.sessionToken.options,\n\t\t\t);\n\t\t} catch (e) {\n\t\t\tc.context.logger.error(\"Unable to set session cookie\", e);\n\t\t\tconst url = new URL(currentURL || callbackURL);\n\t\t\turl.searchParams.set(\"error\", \"unable_to_create_session\");\n\t\t\tthrow c.redirect(url.toString());\n\t\t}\n\t\tthrow c.redirect(callbackURL);\n\t},\n);\n","export const HIDE_ON_CLIENT_METADATA = {\n\tonClient: \"hide\" as const,\n};\n","import { alphabet, generateRandomString } from \"oslo/crypto\";\nexport const generateId = () => {\n\treturn generateRandomString(36, alphabet(\"a-z\", \"0-9\"));\n};\n","import { z } from \"zod\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const signOut = createAuthEndpoint(\n\t\"/sign-out\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z\n\t\t\t.object({\n\t\t\t\tcallbackURL: z.string().optional(),\n\t\t\t})\n\t\t\t.optional(),\n\t},\n\tasync (ctx) => {\n\t\tconst sessionCookieToken = await ctx.getSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\tif (!sessionCookieToken) {\n\t\t\treturn ctx.json(null);\n\t\t}\n\t\tawait ctx.context.internalAdapter.deleteSession(sessionCookieToken);\n\t\tctx.setCookie(ctx.context.authCookies.sessionToken.name, \"\", {\n\t\t\tmaxAge: 0,\n\t\t});\n\t\treturn ctx.json(null, {\n\t\t\tbody: {\n\t\t\t\tredirect: !!ctx.body?.callbackURL,\n\t\t\t\turl: ctx.body?.callbackURL,\n\t\t\t},\n\t\t});\n\t},\n);\n","import { TimeSpan } from \"oslo\";\nimport { createJWT } from \"oslo/jwt\";\nimport { validateJWT } from \"oslo/jwt\";\nimport { Argon2id } from \"oslo/password\";\nimport { z } from \"zod\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const forgetPassword = createAuthEndpoint(\n\t\"/forget-password\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\t/**\n\t\t\t * The email address of the user to send a password reset email to.\n\t\t\t */\n\t\t\temail: z.string().email(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tif (!ctx.context.options.emailAndPassword?.sendResetPasswordToken) {\n\t\t\tctx.context.logger.error(\n\t\t\t\t\"Reset password isn't enabled.Please pass an emailAndPassword.sendResetPasswordToken function to your auth config!\",\n\t\t\t);\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tstatusText: \"RESET_PASSWORD_EMAIL_NOT_SENT\",\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Reset password isn't enabled\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tconst { email } = ctx.body;\n\t\tconst user = await ctx.context.internalAdapter.findUserByEmail(email);\n\t\tif (!user) {\n\t\t\treturn ctx.json(\n\t\t\t\t{\n\t\t\t\t\terror: \"User not found\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"USER_NOT_FOUND\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tconst token = await createJWT(\n\t\t\t\"HS256\",\n\t\t\tBuffer.from(ctx.context.secret),\n\t\t\t{\n\t\t\t\temail: user.user.email,\n\t\t\t},\n\t\t\t{\n\t\t\t\texpiresIn: new TimeSpan(1, \"h\"),\n\t\t\t\tissuer: \"better-auth\",\n\t\t\t\tsubject: \"forget-password\",\n\t\t\t\taudiences: [user.user.email],\n\t\t\t\tincludeIssuedTimestamp: true,\n\t\t\t},\n\t\t);\n\t\tawait ctx.context.options.emailAndPassword.sendResetPasswordToken(\n\t\t\ttoken,\n\t\t\tuser.user,\n\t\t);\n\t\treturn ctx.json({\n\t\t\tstatus: true,\n\t\t});\n\t},\n);\n\nexport const resetPassword = createAuthEndpoint(\n\t\"/reset-password\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\ttoken: z.string(),\n\t\t\tnewPassword: z.string(),\n\t\t\tcallbackURL: z.string().optional(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tconst { token, newPassword } = ctx.body;\n\t\ttry {\n\t\t\tconst jwt = await validateJWT(\n\t\t\t\t\"HS256\",\n\t\t\t\tBuffer.from(ctx.context.secret),\n\t\t\t\ttoken,\n\t\t\t);\n\t\t\tconst email = z\n\t\t\t\t.string()\n\t\t\t\t.email()\n\t\t\t\t.parse((jwt.payload as { email: string }).email);\n\t\t\tconst user = await ctx.context.internalAdapter.findUserByEmail(email);\n\t\t\tif (!user) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"USER_NOT_FOUND\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (\n\t\t\t\tnewPassword.length <\n\t\t\t\t\t(ctx.context.options.emailAndPassword?.minPasswordLength || 8) ||\n\t\t\t\tnewPassword.length >\n\t\t\t\t\t(ctx.context.options.emailAndPassword?.maxPasswordLength || 32)\n\t\t\t) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"INVALID_PASSWORD_LENGTH\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"Password length must be between 8 and 32\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst argon2id = new Argon2id();\n\t\t\tconst hashedPassword = await argon2id.hash(newPassword);\n\t\t\tconst updatedUser = await ctx.context.internalAdapter.updatePassword(\n\t\t\t\tuser.user.id,\n\t\t\t\thashedPassword,\n\t\t\t);\n\t\t\tif (!updatedUser) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 500,\n\t\t\t\t\tstatusText: \"INTERNAL_SERVER_ERROR\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"Internal server error\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn ctx.json({\n\t\t\t\tstatus: true,\n\t\t\t\turl: ctx.body.callbackURL,\n\t\t\t\tredirect: !!ctx.body.callbackURL,\n\t\t\t});\n\t\t} catch (e) {\n\t\t\tconsole.log(e);\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tstatusText: \"INVALID_TOKEN\",\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Invalid token\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t},\n);\n","import { TimeSpan } from \"oslo\";\nimport { createJWT, validateJWT } from \"oslo/jwt\";\nimport { z } from \"zod\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const sendVerificationEmail = createAuthEndpoint(\n\t\"/send-verification-email\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\temail: z.string().email(),\n\t\t\tcallbackURL: z.string().optional(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tif (!ctx.context.options.emailAndPassword?.sendVerificationEmail) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tstatusText: \"VERIFICATION_EMAIL_NOT_SENT\",\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Verification email isn't enabled\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tconst { email } = ctx.body;\n\t\tconst token = await createJWT(\n\t\t\t\"HS256\",\n\t\t\tBuffer.from(ctx.context.secret),\n\t\t\t{\n\t\t\t\temail: email.toLowerCase(),\n\t\t\t},\n\t\t\t{\n\t\t\t\texpiresIn: new TimeSpan(1, \"h\"),\n\t\t\t\tissuer: \"better-auth\",\n\t\t\t\tsubject: \"verify-email\",\n\t\t\t\taudiences: [email],\n\t\t\t\tincludeIssuedTimestamp: true,\n\t\t\t},\n\t\t);\n\t\tconst url = `${ctx.context.baseURL}/verify-email?token=${token}?callbackURL=${ctx.body.callbackURL}`;\n\t\tawait ctx.context.options.emailAndPassword.sendVerificationEmail(\n\t\t\temail,\n\t\t\turl,\n\t\t);\n\t\treturn ctx.json({\n\t\t\tstatus: true,\n\t\t});\n\t},\n);\n\nexport const verifyEmail = createAuthEndpoint(\n\t\"/verify-email\",\n\t{\n\t\tmethod: \"GET\",\n\t\tquery: z.object({\n\t\t\ttoken: z.string(),\n\t\t\tcallbackURL: z.string(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tconst { token } = ctx.query;\n\t\ttry {\n\t\t\tconst jwt = await validateJWT(\n\t\t\t\t\"HS256\",\n\t\t\t\tBuffer.from(ctx.context.secret),\n\t\t\t\ttoken,\n\t\t\t);\n\t\t\tconst schema = z.object({\n\t\t\t\temail: z.string().email(),\n\t\t\t});\n\t\t\tconst parsed = schema.parse(jwt.payload);\n\t\t\tconst user = await ctx.context.internalAdapter.findUserByEmail(\n\t\t\t\tparsed.email,\n\t\t\t);\n\t\t\tif (!user) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"USER_NOT_FOUND\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst account = user.accounts.find((a) => a.providerId === \"credential\");\n\t\t\tif (!account) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"ACCOUNT_NOT_FOUND\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"Account not found\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tawait ctx.context.internalAdapter.updateUserByEmail(parsed.email, {\n\t\t\t\temailVerified: true,\n\t\t\t});\n\t\t\tif (ctx.query.callbackURL) {\n\t\t\t\tthrow ctx.redirect(ctx.query.callbackURL);\n\t\t\t}\n\t\t\treturn ctx.json({\n\t\t\t\tstatus: true,\n\t\t\t});\n\t\t} catch (e) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tstatusText: \"INVALID_TOKEN\",\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Invalid token\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t},\n);\n","import { alphabet, generateRandomString } from \"oslo/crypto\";\nimport { HIDE_ON_CLIENT_METADATA } from \"../../client/client-utils\";\nimport { hs256 } from \"../../crypto\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const getCSRFToken = createAuthEndpoint(\n\t\"/csrf\",\n\t{\n\t\tmethod: \"GET\",\n\t\tmetadata: HIDE_ON_CLIENT_METADATA,\n\t},\n\tasync (ctx) => {\n\t\tconst csrfToken = await ctx.getSignedCookie(\n\t\t\tctx.context.authCookies.csrfToken.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\tif (csrfToken) {\n\t\t\treturn {\n\t\t\t\tcsrfToken,\n\t\t\t};\n\t\t}\n\t\tconst token = generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\"));\n\t\tconst hash = await hs256(ctx.context.secret, token);\n\t\tconst cookie = `${token}!${hash}`;\n\t\tawait ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.csrfToken.name,\n\t\t\tcookie,\n\t\t\tctx.context.secret,\n\t\t\tctx.context.authCookies.csrfToken.options,\n\t\t);\n\t\treturn {\n\t\t\tcsrfToken: token,\n\t\t};\n\t},\n);\n","import { createAuthEndpoint } from \"../call\";\n\nexport const ok = createAuthEndpoint(\n\t\"/ok\",\n\t{\n\t\tmethod: \"GET\",\n\t},\n\tasync (ctx) => {\n\t\treturn ctx.json({\n\t\t\tok: true,\n\t\t});\n\t},\n);\n\nexport const welcome = createAuthEndpoint(\n\t\"/welcome/ok\",\n\t{\n\t\tmethod: \"GET\",\n\t},\n\tasync () => {\n\t\treturn new Response(\"Welcome to Better Auth\");\n\t},\n);\n","import { alphabet, generateRandomString } from \"oslo/crypto\";\nimport { Argon2id } from \"oslo/password\";\nimport { z } from \"zod\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const signUpEmail = createAuthEndpoint(\n\t\"/sign-up/email\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\tname: z.string(),\n\t\t\temail: z.string().email(),\n\t\t\tpassword: z.string(),\n\t\t\timage: z.string().optional(),\n\t\t\tcallbackURL: z.string().optional(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tif (!ctx.context.options.emailAndPassword?.enabled) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Email and password is not enabled\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tconst { name, email, password, image } = ctx.body;\n\t\tconst minPasswordLength =\n\t\t\tctx.context.options?.emailAndPassword?.minPasswordLength || 8;\n\t\tif (password.length < minPasswordLength) {\n\t\t\tctx.context.logger.error(\"Password is too short\");\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tbody: { message: \"Password is too short\" },\n\t\t\t});\n\t\t}\n\t\tconst argon2id = new Argon2id();\n\t\tconst dbUser = await ctx.context.internalAdapter.findUserByEmail(email);\n\t\t/**\n\t\t * hash first to avoid timing attacks\n\t\t */\n\t\tconst hash = await argon2id.hash(password);\n\t\tif (dbUser?.user) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"User already exists\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tconst createdUser = await ctx.context.internalAdapter.createUser({\n\t\t\tid: generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\")),\n\t\t\temail: email.toLowerCase(),\n\t\t\tname,\n\t\t\timage,\n\t\t\temailVerified: false,\n\t\t\tcreatedAt: new Date(),\n\t\t\tupdatedAt: new Date(),\n\t\t});\n\t\t/**\n\t\t * Link the account to the user\n\t\t */\n\t\tawait ctx.context.internalAdapter.linkAccount({\n\t\t\tid: generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\")),\n\t\t\tuserId: createdUser.id,\n\t\t\tproviderId: \"credential\",\n\t\t\taccountId: createdUser.id,\n\t\t\tpassword: hash,\n\t\t});\n\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\tcreatedUser.id,\n\t\t\tctx.request,\n\t\t);\n\t\tawait ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tsession.id,\n\t\t\tctx.context.secret,\n\t\t\tctx.context.authCookies.sessionToken.options,\n\t\t);\n\t\treturn ctx.json(\n\t\t\t{\n\t\t\t\tuser: createdUser,\n\t\t\t\tsession,\n\t\t\t},\n\t\t\t{\n\t\t\t\tbody: ctx.body.callbackURL\n\t\t\t\t\t? {\n\t\t\t\t\t\t\turl: ctx.body.callbackURL,\n\t\t\t\t\t\t\tredirect: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tuser: createdUser,\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t},\n\t\t\t},\n\t\t);\n\t},\n);\n","import { createAuthEndpoint } from \"../call\";\n\nconst html = (errorCode: string = \"Unknown\") => `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Authentication Error</title>\n <style>\n :root {\n --bg-color: #f8f9fa;\n --text-color: #212529;\n --accent-color: #000000;\n --error-color: #dc3545;\n --border-color: #e9ecef;\n }\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n background-color: var(--bg-color);\n color: var(--text-color);\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100vh;\n margin: 0;\n line-height: 1.5;\n }\n .error-container {\n background-color: #ffffff;\n border-radius: 12px;\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);\n padding: 2.5rem;\n text-align: center;\n max-width: 90%;\n width: 400px;\n }\n h1 {\n color: var(--error-color);\n font-size: 1.75rem;\n margin-bottom: 1rem;\n font-weight: 600;\n }\n p {\n margin-bottom: 1.5rem;\n color: #495057;\n }\n .btn {\n background-color: var(--accent-color);\n color: #ffffff;\n text-decoration: none;\n padding: 0.75rem 1.5rem;\n border-radius: 6px;\n transition: all 0.3s ease;\n display: inline-block;\n font-weight: 500;\n border: 2px solid var(--accent-color);\n }\n .btn:hover {\n background-color: #131721;\n }\n .error-code {\n font-size: 0.875rem;\n color: #6c757d;\n margin-top: 1.5rem;\n padding-top: 1.5rem;\n border-top: 1px solid var(--border-color);\n }\n .icon {\n font-size: 3rem;\n margin-bottom: 1rem;\n }\n </style>\n</head>\n<body>\n <div class=\"error-container\">\n <div class=\"icon\">⚠️</div>\n <h1>Better Auth Error</h1>\n <p>We encountered an issue while processing your request. Please try again or contact the application owner if the problem persists.</p>\n <a href=\"#\" id=\"returnLink\" class=\"btn\">Return to Application</a>\n <div class=\"error-code\">Error Code: <span id=\"errorCode\">${errorCode}</span></div>\n </div>\n</body>\n</html>`;\n\nexport const error = createAuthEndpoint(\n\t\"/error\",\n\t{\n\t\tmethod: \"GET\",\n\t},\n\tasync (c) => {\n\t\tconst query =\n\t\t\tnew URL(c.request?.url || \"\").searchParams.get(\"error\") || \"Unknown\";\n\t\treturn new Response(html(query), {\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"text/html\",\n\t\t\t},\n\t\t});\n\t},\n);\n","import Database from \"better-sqlite3\";\nimport { Kysely } from \"kysely\";\nimport {\n\ttype Dialect,\n\tMysqlDialect,\n\tPostgresDialect,\n\tSqliteDialect,\n} from \"kysely\";\nimport { createPool } from \"mysql2\";\nimport pg from \"pg\";\nimport type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\nimport type { Adapter, Where } from \"../types/adapter\";\n\nconst { Pool } = pg;\n\nfunction convertWhere(w?: Where[]) {\n\tif (!w)\n\t\treturn {\n\t\t\tand: null,\n\t\t\tor: null,\n\t\t};\n\tconst and = w\n\t\t?.filter((w) => w.connector === \"AND\" || !w.connector)\n\t\t.reduce(\n\t\t\t(acc, w) =>\n\t\t\t\t({\n\t\t\t\t\t...acc,\n\t\t\t\t\t[w.field]: w.value,\n\t\t\t\t}) as any,\n\t\t\t{},\n\t\t);\n\tconst or = w\n\t\t?.filter((w) => w.connector === \"OR\")\n\t\t.reduce(\n\t\t\t(acc, w) =>\n\t\t\t\t({\n\t\t\t\t\t...acc,\n\t\t\t\t\t[w.field]: w.value,\n\t\t\t\t}) as any,\n\t\t\t{},\n\t\t);\n\treturn {\n\t\tand: Object.keys(and).length ? and : null,\n\t\tor: Object.keys(or).length ? or : null,\n\t};\n}\n\nfunction transformTo(\n\tval: any,\n\tfields: Record<string, FieldAttribute>,\n\ttransform: KyselyAdapterConfig[\"transform\"],\n) {\n\tfor (const key in val) {\n\t\tif (\n\t\t\tval[key] === 0 &&\n\t\t\tfields[key]?.type === \"boolean\" &&\n\t\t\ttransform?.boolean\n\t\t) {\n\t\t\tval[key] = false;\n\t\t}\n\t\tif (\n\t\t\tval[key] === 1 &&\n\t\t\tfields[key]?.type === \"boolean\" &&\n\t\t\ttransform?.boolean\n\t\t) {\n\t\t\tval[key] = true;\n\t\t}\n\t\tif (fields[key]?.type === \"date\") {\n\t\t\tif (!(val[key] instanceof Date)) {\n\t\t\t\tval[key] = new Date(val[key]);\n\t\t\t}\n\t\t}\n\t}\n\treturn val;\n}\n\nfunction transformFrom(val: any, transform: KyselyAdapterConfig[\"transform\"]) {\n\tfor (const key in val) {\n\t\tif (typeof val[key] === \"boolean\" && transform?.boolean) {\n\t\t\tval[key] = val[key] ? 1 : 0;\n\t\t}\n\t\tif (val[key] instanceof Date) {\n\t\t\tval[key] = val[key].toISOString();\n\t\t}\n\t}\n\treturn val;\n}\n\nexport interface KyselyAdapterConfig {\n\t/**\n\t * Transform dates and booleans for sqlite.\n\t */\n\ttransform?: {\n\t\tschema: {\n\t\t\t[table: string]: Record<string, FieldAttribute>;\n\t\t};\n\t\tboolean: boolean;\n\t\tdate: boolean;\n\t};\n}\n\nexport const kyselyAdapter = (\n\tdb: Kysely<any>,\n\tconfig?: KyselyAdapterConfig,\n): Adapter => {\n\treturn {\n\t\tasync create(data) {\n\t\t\tlet { model, data: val, select } = data;\n\t\t\tif (config?.transform) {\n\t\t\t\tval = transformFrom(val, config.transform);\n\t\t\t}\n\t\t\tlet res = await db\n\t\t\t\t.insertInto(model)\n\t\t\t\t.values(val as any)\n\t\t\t\t.returningAll()\n\t\t\t\t.executeTakeFirst();\n\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\tres = schema ? transformTo(val, schema, config.transform) : res;\n\t\t\t}\n\n\t\t\tif (select?.length) {\n\t\t\t\tconst data = res\n\t\t\t\t\t? select.reduce((acc, cur) => {\n\t\t\t\t\t\t\tif (res?.[cur]) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t[cur]: res[cur],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t}, {} as any)\n\t\t\t\t\t: null;\n\t\t\t\tres = data;\n\t\t\t}\n\n\t\t\treturn res as any;\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tlet query = db.selectFrom(model).selectAll();\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tlet res = await query.executeTakeFirst();\n\t\t\tif (select?.length) {\n\t\t\t\tconst data = res\n\t\t\t\t\t? select.reduce((acc, cur) => {\n\t\t\t\t\t\t\tif (res?.[cur]) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t[cur]: res[cur],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t}, {} as any)\n\t\t\t\t\t: null;\n\t\t\t\tres = data;\n\t\t\t}\n\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\tres = res && schema ? transformTo(res, schema, config.transform) : res;\n\n\t\t\t\treturn res || null;\n\t\t\t}\n\t\t\treturn (res || null) as any;\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tlet query = db.selectFrom(model);\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tconst res = await query.selectAll().execute();\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\treturn schema\n\t\t\t\t\t? res.map((v) => transformTo(v, schema, config.transform))\n\t\t\t\t\t: res;\n\t\t\t}\n\t\t\treturn res as any;\n\t\t},\n\t\tasync update(data) {\n\t\t\tlet { model, where, update: val } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\n\t\t\tif (config?.transform) {\n\t\t\t\tval = transformFrom(val, config.transform);\n\t\t\t}\n\n\t\t\tlet query = db.updateTable(model).set(val);\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tconst res = await query.returningAll().executeTakeFirst();\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\treturn schema ? transformTo(res, schema, config.transform) : res;\n\t\t\t}\n\t\t\treturn res as any;\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tlet query = db.deleteFrom(model);\n\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\n\t\t\tawait query.execute();\n\t\t},\n\t};\n};\n\nexport const getDialect = (config: BetterAuthOptions) => {\n\tif (!config.database) {\n\t\treturn null;\n\t}\n\tlet dialect: Dialect | null = null;\n\tif (\"provider\" in config.database) {\n\t\tconst provider = config.database.provider;\n\t\tconst connectionString = config.database.url.trim();\n\t\tif (provider === \"postgres\") {\n\t\t\tconst pool = new Pool({\n\t\t\t\tconnectionString,\n\t\t\t});\n\t\t\tdialect = new PostgresDialect({\n\t\t\t\tpool,\n\t\t\t});\n\t\t}\n\t\tif (provider === \"mysql\") {\n\t\t\tconst params = new URL(connectionString);\n\t\t\tconst pool = createPool({\n\t\t\t\thost: params.hostname,\n\t\t\t\tuser: params.username,\n\t\t\t\tpassword: params.password,\n\t\t\t\tdatabase: params.pathname.split(\"/\")[1],\n\t\t\t\tport: Number(params.port),\n\t\t\t});\n\t\t\tdialect = new MysqlDialect({ pool });\n\t\t}\n\n\t\tif (provider === \"sqlite\") {\n\t\t\tconst db = new Database(connectionString);\n\t\t\tdialect = new SqliteDialect({\n\t\t\t\tdatabase: db,\n\t\t\t});\n\t\t}\n\t}\n\treturn dialect;\n};\n\nexport const createKyselyAdapter = (config: BetterAuthOptions) => {\n\tconst dialect = getDialect(config);\n\tif (!dialect) {\n\t\treturn null;\n\t}\n\tconst db = new Kysely<any>({\n\t\tdialect,\n\t});\n\treturn db;\n};\n\nexport const getDatabaseType = (config: BetterAuthOptions) => {\n\tif (\"provider\" in config.database) {\n\t\treturn config.database.provider;\n\t}\n\tif (\"dialect\" in config.database) {\n\t\tif (config.database.dialect instanceof PostgresDialect) {\n\t\t\treturn \"postgres\";\n\t\t}\n\t\tif (config.database.dialect instanceof MysqlDialect) {\n\t\t\treturn \"mysql\";\n\t\t}\n\t\tif (config.database.dialect instanceof SqliteDialect) {\n\t\t\treturn \"sqlite\";\n\t\t}\n\t}\n\treturn \"sqlite\";\n};\n","import type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\n\nexport type BetterAuthDbSchema = Record<\n\tstring,\n\t{\n\t\ttableName: string;\n\t\tfields: Record<string, FieldAttribute>;\n\t\tdisableMigrations?: boolean;\n\t}\n>;\n\nexport const getAuthTables = (options: BetterAuthOptions) => {\n\tconst pluginSchema = options.plugins?.reduce((acc, plugin) => {\n\t\tconst schema = plugin.schema;\n\t\treturn {\n\t\t\t...acc,\n\t\t\t...schema,\n\t\t};\n\t}, {});\n\n\treturn {\n\t\t...pluginSchema,\n\t\tuser: {\n\t\t\ttableName: options.user?.modelName || \"user\",\n\t\t\tfields: {\n\t\t\t\tname: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\temail: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\temailVerified: {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdefaultValue: () => false,\n\t\t\t\t},\n\t\t\t\timage: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tsession: {\n\t\t\ttableName: options.session?.modelName || \"session\",\n\t\t\tfields: {\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t},\n\t\t\t\tipAddress: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tuserAgent: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\taccount: {\n\t\t\ttableName: options.account?.modelName || \"account\",\n\t\t\tfields: {\n\t\t\t\taccountId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\tproviderId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\taccessToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\trefreshToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tidToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\taccessTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\trefreshTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t} satisfies BetterAuthDbSchema;\n};\n","import { BetterAuthError } from \"../error/better-auth-error\";\nimport type { BetterAuthOptions } from \"../types\";\nimport type { Adapter } from \"../types/adapter\";\nimport { getAuthTables } from \"./get-tables\";\nimport { createKyselyAdapter, getDatabaseType, kyselyAdapter } from \"./kysely\";\n\nexport function getAdapter(options: BetterAuthOptions): Adapter {\n\tif (!options.database) {\n\t\tthrow new BetterAuthError(\"Database configuration is required\");\n\t}\n\tif (\"provider\" in options.database) {\n\t\tconst db = createKyselyAdapter(options);\n\t\tif (!db) {\n\t\t\tthrow new BetterAuthError(\"Failed to initialize database adapter\");\n\t\t}\n\t\tconst tables = getAuthTables(options);\n\t\treturn kyselyAdapter(db, {\n\t\t\ttransform: {\n\t\t\t\tschema: {\n\t\t\t\t\t[tables.user.tableName]: tables.user.fields,\n\t\t\t\t\t[tables.session.tableName]: tables.session.fields,\n\t\t\t\t\t[tables.account.tableName]: tables.account.fields,\n\t\t\t\t},\n\t\t\t\tdate: true,\n\t\t\t\tboolean: getDatabaseType(options) === \"sqlite\",\n\t\t\t},\n\t\t});\n\t}\n\treturn options.database;\n}\n","import { alphabet, generateRandomString } from \"oslo/crypto\";\nimport type { BetterAuthOptions } from \"../types\";\nimport type { Adapter } from \"../types/adapter\";\nimport { getDate } from \"../utils/date\";\nimport { getAuthTables } from \"./get-tables\";\nimport type { Account, Session, User } from \"./schema\";\n\nexport const createInternalAdapter = (\n\tadapter: Adapter,\n\toptions: BetterAuthOptions,\n) => {\n\tconst sessionExpiration = options.session?.expiresIn || 60 * 60 * 24 * 7; // 7 days\n\tconst tables = getAuthTables(options);\n\treturn {\n\t\tcreateOAuthUser: async (user: User, account: Account) => {\n\t\t\ttry {\n\t\t\t\tconst createdUser = await adapter.create({\n\t\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\t\tdata: user,\n\t\t\t\t});\n\t\t\t\tconst createdAccount = await adapter.create({\n\t\t\t\t\tmodel: tables.account.tableName,\n\t\t\t\t\tdata: account,\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tuser: createdUser,\n\t\t\t\t\taccount: createdAccount,\n\t\t\t\t};\n\t\t\t} catch (e) {\n\t\t\t\tconsole.log(e);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t},\n\t\tcreateUser: async (user: User) => {\n\t\t\tconst createdUser = await adapter.create<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\tdata: user,\n\t\t\t});\n\t\t\treturn createdUser;\n\t\t},\n\t\tcreateSession: async (userId: string, request?: Request) => {\n\t\t\tconst data: Session = {\n\t\t\t\tid: generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\")),\n\t\t\t\tuserId,\n\t\t\t\texpiresAt: getDate(sessionExpiration),\n\t\t\t\tipAddress: request?.headers.get(\"x-forwarded-for\") || \"\",\n\t\t\t\tuserAgent: request?.headers.get(\"user-agent\") || \"\",\n\t\t\t};\n\t\t\tconst session = adapter.create<Session>({\n\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\tdata,\n\t\t\t});\n\t\t\treturn session;\n\t\t},\n\t\tfindSession: async (sessionId: string) => {\n\t\t\tconst session = await adapter.findOne<Session>({\n\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: sessionId,\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!session) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst user = await adapter.findOne<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: session.userId,\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tsession,\n\t\t\t\tuser,\n\t\t\t};\n\t\t},\n\t\tupdateSession: async (session: Session) => {\n\t\t\tconst updateAge =\n\t\t\t\toptions.session?.updateAge === undefined\n\t\t\t\t\t? 1000 // 1 hour update age\n\t\t\t\t\t: options.session?.updateAge;\n\t\t\tconst updateDate = updateAge === 0 ? 0 : getDate(updateAge).valueOf();\n\t\t\tconst maxAge = getDate(sessionExpiration);\n\t\t\tconst shouldBeUpdated =\n\t\t\t\tsession.expiresAt.valueOf() - maxAge.valueOf() + updateDate <=\n\t\t\t\tDate.now();\n\t\t\tif (shouldBeUpdated) {\n\t\t\t\tconst updatedSession = await adapter.create<Session>({\n\t\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\t...session,\n\t\t\t\t\t\tid: generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\")),\n\t\t\t\t\t\texpiresAt: new Date(Date.now() + sessionExpiration),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tawait adapter.update<Session>({\n\t\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\t\twhere: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\t\tvalue: session.id,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * update the session to expire in 2 minute. This is to prevent\n\t\t\t\t\t\t * the session from expiring too quickly and logging the user out.\n\t\t\t\t\t\t */\n\t\t\t\t\t\texpiresAt: new Date(Date.now() + 1000 * 60 * 2),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn updatedSession;\n\t\t\t}\n\n\t\t\treturn session;\n\t\t},\n\t\tdeleteSession: async (id: string) => {\n\t\t\tconst session = await adapter.delete<Session>({\n\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tvalue: id,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\treturn session;\n\t\t},\n\t\tfindUserByEmail: async (email: string) => {\n\t\t\tconst user = await adapter.findOne<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: email.toLowerCase(),\n\t\t\t\t\t\tfield: \"email\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) return null;\n\t\t\tconst accounts = await adapter.findMany<Account>({\n\t\t\t\tmodel: tables.account.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tuser,\n\t\t\t\taccounts,\n\t\t\t};\n\t\t},\n\t\tfindUserById: async (userId: string) => {\n\t\t\tconst user = await adapter.findOne<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tvalue: userId,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\treturn user;\n\t\t},\n\t\tlinkAccount: async (account: Account) => {\n\t\t\tconst _account = await adapter.create<Account>({\n\t\t\t\tmodel: tables.account.tableName,\n\t\t\t\tdata: account,\n\t\t\t});\n\t\t\treturn _account;\n\t\t},\n\t\tupdateUserByEmail: async (\n\t\t\temail: string,\n\t\t\tdata: Partial<User & Record<string, any>>,\n\t\t) => {\n\t\t\tconst user = await adapter.update<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: email,\n\t\t\t\t\t\tfield: \"email\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tupdate: data,\n\t\t\t});\n\t\t\treturn user;\n\t\t},\n\t\tupdatePassword: async (userId: string, password: string) => {\n\t\t\tconst account = await adapter.update<Account>({\n\t\t\t\tmodel: tables.account.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: userId,\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"providerId\",\n\t\t\t\t\t\tvalue: \"credential\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tupdate: {\n\t\t\t\t\tpassword,\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn account;\n\t\t},\n\t};\n};\n\nexport type InternalAdapter = ReturnType<typeof createInternalAdapter>;\n","export const getDate = (span: number) => {\n\tconst date = new Date();\n\treturn new Date(date.getTime() + span);\n};\n","import type { ZodSchema } from \"zod\";\n\nexport const createFieldAttribute = <\n\tT extends FieldType,\n\tC extends Omit<FieldAttributeConfig<T>, \"type\">,\n>(\n\ttype: T,\n\tconfig?: C,\n) => {\n\treturn {\n\t\ttype,\n\t\t...config,\n\t} satisfies FieldAttribute<T>;\n};\n\nexport type FieldAttribute<T extends FieldType = FieldType> = {\n\ttype: T;\n} & FieldAttributeConfig<T>;\n\nexport type FieldType = \"string\" | \"number\" | \"boolean\" | \"date\";\n\nexport type InferValueType<T extends FieldType> = T extends \"string\"\n\t? string\n\t: T extends \"number\"\n\t\t? number\n\t\t: T extends \"boolean\"\n\t\t\t? boolean\n\t\t\t: T extends \"date\"\n\t\t\t\t? Date\n\t\t\t\t: never;\n\nexport type InferFieldOutput<T extends FieldAttribute> =\n\tT[\"returned\"] extends false\n\t\t? never\n\t\t: T[\"required\"] extends false\n\t\t\t? InferValueType<T[\"type\"]> | undefined\n\t\t\t: InferValueType<T[\"type\"]>;\n\nexport type FieldAttributeConfig<T extends FieldType = FieldType> = {\n\t/**\n\t * if the field should be required on a new record.\n\t * @default false\n\t */\n\trequired?: boolean;\n\t/**\n\t * If the value should be returned on a response body.\n\t * @default true\n\t */\n\treturned?: boolean;\n\t/**\n\t * If the value should be hashed when it's stored.\n\t * @default false\n\t */\n\thashValue?: boolean;\n\t/**\n\t * Default value for the field\n\t *\n\t * Note: This will not create a default value on the database level. It will only\n\t * be used when creating a new record.\n\t */\n\tdefaultValue?: InferValueType<T> | (() => InferValueType<T>);\n\t/**\n\t * transform the value before storing it.\n\t */\n\ttransform?: (value: InferValueType<T>) => InferValueType<T>;\n\t/**\n\t * Reference to another model.\n\t */\n\treferences?: {\n\t\t/**\n\t\t * The model to reference.\n\t\t */\n\t\tmodel: string;\n\t\t/**\n\t\t * The field on the referenced model.\n\t\t */\n\t\tfield: string;\n\t\t/**\n\t\t * The action to perform when the reference is deleted.\n\t\t * @default \"cascade\"\n\t\t */\n\t\tonDelete?:\n\t\t\t| \"no action\"\n\t\t\t| \"restrict\"\n\t\t\t| \"cascade\"\n\t\t\t| \"set null\"\n\t\t\t| \"set default\";\n\t};\n\tunique?: boolean;\n\t/**\n\t * A zod schema to validate the value.\n\t */\n\tvalidator?: ZodSchema;\n};\n","import type { CookieOptions } from \"better-call\";\nimport { TimeSpan } from \"oslo\";\nimport type { BetterAuthOptions } from \"../types/options\";\n\nexport function getCookies(options: BetterAuthOptions) {\n\tconst secure =\n\t\t!!options.advanced?.useSecureCookies ||\n\t\tprocess.env.NODE_ENV === \"production\";\n\tconst secureCookiePrefix = secure ? \"__Secure-\" : \"\";\n\tconst cookiePrefix = \"better-auth\";\n\tconst sessionMaxAge = new TimeSpan(7, \"d\").seconds();\n\treturn {\n\t\tsessionToken: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.session_token`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: sessionMaxAge,\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\tcsrfToken: {\n\t\t\tname: `${secureCookiePrefix ? \"__Host-\" : \"\"}${cookiePrefix}.csrf_token`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: 60 * 60 * 24 * 7,\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\tstate: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.state`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: 60 * 15, // 15 minutes in seconds\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\tpkCodeVerifier: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.pk_code_verifier`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: 60 * 15, // 15 minutes in seconds\n\t\t\t} as CookieOptions,\n\t\t},\n\t\tnonce: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.nonce`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: 60 * 15, // 15 minutes in seconds\n\t\t\t} as CookieOptions,\n\t\t},\n\t};\n}\n\nexport function createCookieGetter(options: BetterAuthOptions) {\n\tconst secure =\n\t\t!!options.advanced?.useSecureCookies ||\n\t\tprocess.env.NODE_ENV === \"production\";\n\tconst secureCookiePrefix = secure ? \"__Secure-\" : \"\";\n\tconst cookiePrefix = \"better-auth\";\n\tfunction getCookie(cookieName: string, options?: CookieOptions) {\n\t\treturn {\n\t\t\tname:\n\t\t\t\tprocess.env.NODE_ENV === \"production\"\n\t\t\t\t\t? `${secureCookiePrefix}${cookiePrefix}.${cookieName}`\n\t\t\t\t\t: `${cookiePrefix}.${cookieName}`,\n\t\t\toptions: {\n\t\t\t\tsecure,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tmaxAge: 60 * 15, // 15 minutes in seconds\n\t\t\t\t...options,\n\t\t\t} as CookieOptions,\n\t\t};\n\t}\n\treturn getCookie;\n}\nexport type BetterAuthCookies = ReturnType<typeof getCookies>;\n","import { createConsola } from \"consola\";\n\nconst consola = createConsola({\n\tformatOptions: {\n\t\tdate: false,\n\t},\n});\n\nexport const createLogger = (options?: {\n\tdisabled?: boolean;\n}) => {\n\treturn {\n\t\tlog: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.log(\"\", ...args);\n\t\t},\n\t\terror: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.error(\"\", ...args);\n\t\t},\n\t\twarn: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.warn(\"\", ...args);\n\t\t},\n\t\tinfo: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.info(\"\", ...args);\n\t\t},\n\t\tdebug: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.debug(\"\", ...args);\n\t\t},\n\t\tbox: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.box(\"\", ...args);\n\t\t},\n\t\tsuccess: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.success(\"\", ...args);\n\t\t},\n\t\tbreak: (...args: any[]) => {\n\t\t\t!options?.disabled && console.log(\"\\n\");\n\t\t},\n\t};\n};\n\nexport const logger = createLogger();\n","import { createKyselyAdapter } from \"./adapters/kysely\";\nimport { getAdapter } from \"./adapters/utils\";\nimport { createInternalAdapter } from \"./db\";\nimport type { BetterAuthOptions } from \"./types\";\nimport { getBaseURL } from \"./utils/base-url\";\nimport {\n\ttype BetterAuthCookies,\n\tcreateCookieGetter,\n\tgetCookies,\n} from \"./utils/cookies\";\nimport { createLogger } from \"./utils/logger\";\n\nexport const init = (options: BetterAuthOptions) => {\n\tconst adapter = getAdapter(options);\n\tconst db = createKyselyAdapter(options);\n\tconst { baseURL, withPath } = getBaseURL(options.baseURL, options.basePath);\n\n\treturn {\n\t\toptions: {\n\t\t\t...options,\n\t\t\tbaseURL: baseURL,\n\t\t\tbasePath: options.basePath || \"/api/auth\",\n\t\t},\n\t\tbaseURL: withPath,\n\t\tsecret:\n\t\t\toptions.secret ||\n\t\t\tprocess.env.BETTER_AUTH_SECRET ||\n\t\t\tprocess.env.AUTH_SECRET ||\n\t\t\t\"better-auth-secret-123456789\",\n\t\tauthCookies: getCookies(options),\n\t\tlogger: createLogger({\n\t\t\tdisabled: options.disableLog,\n\t\t}),\n\t\tdb,\n\t\tadapter: adapter,\n\t\tinternalAdapter: createInternalAdapter(adapter, options),\n\t\tcreateAuthCookie: createCookieGetter(options),\n\t};\n};\n\nexport type AuthContext = {\n\toptions: BetterAuthOptions;\n\tbaseURL: string;\n\tauthCookies: BetterAuthCookies;\n\tlogger: ReturnType<typeof createLogger>;\n\tdb: ReturnType<typeof createKyselyAdapter>;\n\tadapter: ReturnType<typeof getAdapter>;\n\tinternalAdapter: ReturnType<typeof createInternalAdapter>;\n\tcreateAuthCookie: ReturnType<typeof createCookieGetter>;\n\tsecret: string;\n};\n","import type { UnionToIntersection } from \"./types/helper\";\nimport { router } from \"./api\";\nimport { init } from \"./init\";\nimport type { BetterAuthOptions } from \"./types/options\";\nimport type { BetterAuthPlugin } from \"./types/plugins\";\n\nexport const betterAuth = <O extends BetterAuthOptions>(options: O) => {\n\tconst authContext = init(options);\n\ttype PluginEndpoint = UnionToIntersection<\n\t\tO[\"plugins\"] extends Array<infer T>\n\t\t\t? T extends BetterAuthPlugin\n\t\t\t\t? {\n\t\t\t\t\t\t[key in T[\"id\"]]: T[\"endpoints\"];\n\t\t\t\t\t}\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\tconst { handler, endpoints } = router(authContext);\n\ttype Endpoint = typeof endpoints;\n\n\treturn {\n\t\thandler,\n\t\tapi: endpoints as Endpoint & PluginEndpoint,\n\t\toptions,\n\t};\n};\n\nexport type Auth = {\n\thandler: (request: Request) => Promise<Response>;\n\tapi: ReturnType<typeof router>[\"endpoints\"];\n\toptions: BetterAuthOptions;\n};\n"],"mappings":";AAAA,SAAsC,oBAAoB;;;ACA1D,SAAS,SAAS;AAIX,IAAM,gBAAgB,EAAE,OAAO;AAAA,EACrC,IAAI,EAAE,OAAO;AAAA,EACb,YAAY,EAAE,OAAO;AAAA,EACrB,WAAW,EAAE,OAAO;AAAA,EACpB,QAAQ,EAAE,OAAO;AAAA,EACjB,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC5C,cA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AgB;AACxB,OAAC,SAAS,YAAY,QAAQ,IAAI,IAAI,GAAG,IAAI;AAAA,IAC9C;AAAA,IACA,SAAS,IAAI,SAAgB;AAC5B,OAAC,SAAS,YAAY,QAAQ,QAAQ,IAAI,GAAG,IAAI;AAAA,IAClD;AAAA,IACA,OAAO,IAAI,SAAgB;AAC1B,OAAC,SAAS,YAAY,QAAQ,IAAI,IAAI;AAAA,IACvC;AAAA,EACD;AACD;AAEO,IAAM,SAAS,aAAa;;;AC3B5B,IAAM,OAAO,CAAC,YAA+B;AACnD,QAAM,UAAU,WAAW,OAAO;AAClC,QAAM,KAAK,oBAAoB,OAAO;AACtC,QAAM,EAAE,SAAS,UAAAC,UAAS,IAAI,WAAW,QAAQ,SAAS,QAAQ,QAAQ;AAE1E,SAAO;AAAA,IACN,SAAS;AAAA,MACR,GAAG;AAAA,MACH;AAAA,MACA,UAAU,QAAQ,YAAY;AAAA,IAC/B;AAAA,IACA,SAASA;AAAA,IACT,QACC,QAAQ,UACR,QAAQ,IAAI,sBACZ,QAAQ,IAAI,eACZ;AAAA,IACD,aAAa,WAAW,OAAO;AAAA,IAC/B,QAAQ,aAAa;AAAA,MACpB,UAAU,QAAQ;AAAA,IACnB,CAAC;AAAA,IACD;AAAA,IACA;AAAA,IACA,iBAAiB,sBAAsB,SAAS,OAAO;AAAA,IACvD,kBAAkB,mBAAmB,OAAO;AAAA,EAC7C;AACD;;;AChCO,IAAM,aAAa,CAA8B,YAAe;AACtE,QAAM,cAAc,KAAK,OAAO;AAUhC,QAAM,EAAE,SAAS,UAAU,IAAI,OAAO,WAAW;AAGjD,SAAO;AAAA,IACN;AAAA,IACA,KAAK;AAAA,IACL;AAAA,EACD;AACD;","names":["z","z","APIError","z","error","betterFetch","error","betterFetch","betterFetch","error","betterFetch","betterFetch","error","betterFetch","parseJWT","parseJWT","betterFetch","error","betterFetch","betterFetch","error","betterFetch","betterFetch","error","betterFetch","z","APIError","APIError","z","z","APIError","z","z","Argon2id","z","z","Argon2id","TimeSpan","createJWT","validateJWT","z","z","createJWT","TimeSpan","validateJWT","alphabet","generateRandomString","generateRandomString","alphabet","alphabet","generateRandomString","Argon2id","z","z","Argon2id","generateRandomString","alphabet","ctx","w","data","alphabet","generateRandomString","generateRandomString","alphabet","TimeSpan","options","withPath"]}
|
|
1
|
+
{"version":3,"sources":["../src/api/index.ts","../src/adapters/schema.ts","../src/api/middlewares/csrf.ts","../src/crypto/index.ts","../src/api/call.ts","../src/api/routes/sign-in.ts","../src/social-providers/apple.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/social-providers/utils.ts","../src/social-providers/discord.ts","../src/social-providers/facebook.ts","../src/social-providers/github.ts","../src/social-providers/google.ts","../src/social-providers/spotify.ts","../src/social-providers/twitch.ts","../src/social-providers/twitter.ts","../src/types/provider.ts","../src/social-providers/index.ts","../src/utils/state.ts","../src/api/routes/session.ts","../src/api/routes/callback.ts","../src/client/client-utils.ts","../src/utils/id.ts","../src/api/routes/sign-out.ts","../src/api/routes/forget-password.ts","../src/api/routes/verify-email.ts","../src/api/routes/csrf.ts","../src/api/routes/ok.ts","../src/api/routes/sign-up.ts","../src/api/routes/error.ts","../src/adapters/kysely.ts","../src/adapters/get-tables.ts","../src/adapters/utils.ts","../src/adapters/internal-adapter.ts","../src/utils/date.ts","../src/db/field.ts","../src/utils/cookies.ts","../src/utils/logger.ts","../src/init.ts","../src/auth.ts"],"sourcesContent":["import { type Context, type Endpoint, createRouter } from \"better-call\";\nimport { parseAccount, parseSession, parseUser } from \"../adapters/schema\";\nimport type { AuthContext } from \"../init\";\nimport type { BetterAuthOptions, InferSession, InferUser } from \"../types\";\nimport type { Prettify } from \"../types/helper\";\nimport { csrfMiddleware } from \"./middlewares/csrf\";\nimport {\n\tcallbackOAuth,\n\tforgetPassword,\n\tgetSession,\n\tresetPassword,\n\tsendVerificationEmail,\n\tsignInEmail,\n\tsignInOAuth,\n\tsignOut,\n\tverifyEmail,\n} from \"./routes\";\nimport { getCSRFToken } from \"./routes/csrf\";\nimport { ok, welcome } from \"./routes/ok\";\nimport { signUpEmail } from \"./routes/sign-up\";\nimport { error } from \"./routes/error\";\n\nexport const router = <C extends AuthContext, Option extends BetterAuthOptions>(\n\tctx: C,\n) => {\n\tconst pluginEndpoints = ctx.options.plugins?.reduce(\n\t\t(acc, plugin) => {\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t...plugin.endpoints,\n\t\t\t};\n\t\t},\n\t\t{} as Record<string, any>,\n\t);\n\n\tconst middlewares =\n\t\tctx.options.plugins\n\t\t\t?.map((plugin) =>\n\t\t\t\tplugin.middlewares?.map((m) => {\n\t\t\t\t\tconst middleware = (async (context: any) => {\n\t\t\t\t\t\treturn m.middleware({\n\t\t\t\t\t\t\t...context,\n\t\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\t\t...ctx,\n\t\t\t\t\t\t\t\t...context.context,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}) as Endpoint;\n\t\t\t\t\tmiddleware.path = m.path;\n\t\t\t\t\tmiddleware.options = m.middleware.options;\n\t\t\t\t\tmiddleware.headers = m.middleware.headers;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpath: m.path,\n\t\t\t\t\t\tmiddleware,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.filter((plugin) => plugin !== undefined)\n\t\t\t.flat() || [];\n\n\tasync function typedSession(\n\t\tctx: Context<\n\t\t\t\"/session\",\n\t\t\t{\n\t\t\t\tmethod: \"GET\";\n\t\t\t\trequireHeaders: true;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tconst handler = await getSession(ctx);\n\t\treturn handler as {\n\t\t\tsession: Prettify<InferSession<Option>>;\n\t\t\tuser: Prettify<InferUser<Option>>;\n\t\t} | null;\n\t}\n\ttypedSession.path = getSession.path;\n\ttypedSession.method = getSession.method;\n\ttypedSession.options = getSession.options;\n\ttypedSession.headers = getSession.headers;\n\n\tconst baseEndpoints = {\n\t\tsignInOAuth,\n\t\tcallbackOAuth,\n\t\tgetCSRFToken,\n\t\tgetSession: typedSession,\n\t\tsignOut,\n\t\tsignUpEmail,\n\t\tsignInEmail,\n\t\tforgetPassword,\n\t\tresetPassword,\n\t\tverifyEmail,\n\t\tsendVerificationEmail,\n\t};\n\tconst endpoints = {\n\t\t...baseEndpoints,\n\t\t...pluginEndpoints,\n\t\tok,\n\t\twelcome,\n\t\terror,\n\t};\n\tlet api: Record<string, any> = {};\n\tfor (const [key, value] of Object.entries(endpoints)) {\n\t\tapi[key] = async (context: any) => {\n\t\t\tfor (const plugin of ctx.options.plugins || []) {\n\t\t\t\tif (plugin.hooks?.before) {\n\t\t\t\t\tfor (const hook of plugin.hooks.before) {\n\t\t\t\t\t\tconst match = hook.matcher({\n\t\t\t\t\t\t\t...context,\n\t\t\t\t\t\t\t...value,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (match) {\n\t\t\t\t\t\t\tconst hookRes = await hook.handler(context);\n\t\t\t\t\t\t\tif (hookRes && \"context\" in hookRes) {\n\t\t\t\t\t\t\t\tcontext = {\n\t\t\t\t\t\t\t\t\t...context,\n\t\t\t\t\t\t\t\t\t...hookRes.context,\n\t\t\t\t\t\t\t\t\t...value,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t//@ts-ignore\n\t\t\tconst endpointRes = value({\n\t\t\t\t...context,\n\t\t\t\tcontext: {\n\t\t\t\t\t...ctx,\n\t\t\t\t\t...context.context,\n\t\t\t\t},\n\t\t\t});\n\t\t\tlet response = endpointRes;\n\t\t\tfor (const plugin of ctx.options.plugins || []) {\n\t\t\t\tif (plugin.hooks?.after) {\n\t\t\t\t\tfor (const hook of plugin.hooks.after) {\n\t\t\t\t\t\tconst match = hook.matcher(context);\n\t\t\t\t\t\tif (match) {\n\t\t\t\t\t\t\tconst obj = Object.assign(context, {\n\t\t\t\t\t\t\t\treturned: endpointRes,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tconst hookRes = await hook.handler(obj);\n\t\t\t\t\t\t\tif (hookRes && \"response\" in hookRes) {\n\t\t\t\t\t\t\t\tresponse = hookRes.response as any;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn response;\n\t\t};\n\t\tapi[key].path = value.path;\n\t\tapi[key].method = value.method;\n\t\tapi[key].options = value.options;\n\t\tapi[key].headers = value.headers;\n\t}\n\treturn createRouter(api as typeof baseEndpoints, {\n\t\textraContext: ctx,\n\t\tbasePath: ctx.options.basePath,\n\t\trouterMiddleware: [\n\t\t\t{\n\t\t\t\tpath: \"/**\",\n\t\t\t\tmiddleware: csrfMiddleware,\n\t\t\t},\n\t\t\t...middlewares,\n\t\t],\n\t\t/**\n\t\t * this is to remove any sensitive data from the response\n\t\t */\n\t\tasync transformResponse(res) {\n\t\t\tlet body: Record<string, any> = {};\n\t\t\ttry {\n\t\t\t\tbody = await res.json();\n\t\t\t} catch (e) {\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\tif (body?.user) {\n\t\t\t\tbody.user = parseUser(ctx.options, body.user);\n\t\t\t}\n\t\t\tif (body?.session) {\n\t\t\t\tbody.session = parseSession(ctx.options, body.session);\n\t\t\t}\n\t\t\tif (body?.account) {\n\t\t\t\tbody.account = parseAccount(ctx.options, body.account);\n\t\t\t}\n\t\t\treturn new Response(body ? JSON.stringify(body) : null, {\n\t\t\t\theaders: res.headers,\n\t\t\t\tstatus: res.status,\n\t\t\t\tstatusText: res.statusText,\n\t\t\t});\n\t\t},\n\t\tonError(e) {\n\t\t\tconsole.log(e);\n\t\t},\n\t});\n};\n","import { z } from \"zod\";\nimport type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\n\nexport const accountSchema = z.object({\n\tid: z.string(),\n\tproviderId: z.string(),\n\taccountId: z.string(),\n\tuserId: z.string(),\n\taccessToken: z.string().nullable().optional(),\n\trefreshToken: z.string().nullable().optional(),\n\tidToken: z.string().nullable().optional(),\n\taccessTokenExpiresAt: z.date().nullable().optional(),\n\trefreshTokenExpiresAt: z.date().nullable().optional(),\n\t/**\n\t * Password is only stored in the credential provider\n\t */\n\tpassword: z.string().optional().nullable(),\n});\n\nexport const userSchema = z.object({\n\tid: z.string(),\n\temail: z.string().transform((val) => val.toLowerCase()),\n\temailVerified: z.boolean().default(false),\n\tname: z.string(),\n\timage: z.string().optional(),\n\tcreatedAt: z.date().default(new Date()),\n\tupdatedAt: z.date().default(new Date()),\n});\n\nexport const sessionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\texpiresAt: z.date(),\n\tipAddress: z.string().optional(),\n\tuserAgent: z.string().optional(),\n});\n\nexport type User = z.infer<typeof userSchema>;\nexport type Account = z.infer<typeof accountSchema>;\nexport type Session = z.infer<typeof sessionSchema>;\nexport interface MigrationTable {\n\tname: string;\n\ttimestamp: string;\n}\n\nexport function parseData<T extends Record<string, any>>(\n\tdata: T,\n\tschema: {\n\t\tfields: Record<string, FieldAttribute>;\n\t},\n) {\n\tconst fields = schema.fields;\n\tconst parsedData: Record<string, any> = {};\n\tfor (const key in data) {\n\t\tconst field = fields[key];\n\t\tif (!field) {\n\t\t\tparsedData[key] = data[key];\n\t\t\tcontinue;\n\t\t}\n\t\tif (field.returned === false) {\n\t\t\tcontinue;\n\t\t}\n\t\tparsedData[key] = data[key];\n\t}\n\treturn parsedData as T;\n}\n\nexport function getAllFields(options: BetterAuthOptions, table: string) {\n\tlet schema: Record<string, FieldAttribute> = {};\n\tfor (const plugin of options.plugins || []) {\n\t\tif (plugin.schema && plugin.schema[table]) {\n\t\t\tschema = {\n\t\t\t\t...schema,\n\t\t\t\t...plugin.schema[table].fields,\n\t\t\t};\n\t\t}\n\t}\n\treturn schema;\n}\n\nexport function parseUser(options: BetterAuthOptions, user: User) {\n\tconst schema = getAllFields(options, \"user\");\n\treturn parseData(user, { fields: schema });\n}\n\nexport function parseAccount(options: BetterAuthOptions, account: Account) {\n\tconst schema = getAllFields(options, \"account\");\n\treturn parseData(account, { fields: schema });\n}\n\nexport function parseSession(options: BetterAuthOptions, session: Session) {\n\tconst schema = getAllFields(options, \"session\");\n\treturn parseData(session, { fields: schema });\n}\n","import { APIError } from \"better-call\";\nimport { z } from \"zod\";\nimport { hs256 } from \"../../crypto\";\nimport { createAuthMiddleware } from \"../call\";\n\nexport const csrfMiddleware = createAuthMiddleware(\n\t{\n\t\tbody: z\n\t\t\t.object({\n\t\t\t\tcsrfToken: z.string().optional(),\n\t\t\t})\n\t\t\t.optional(),\n\t},\n\tasync (ctx) => {\n\t\tif (\n\t\t\tctx.request?.method !== \"POST\" ||\n\t\t\tctx.context.options.advanced?.disableCSRFCheck\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst url = new URL(ctx.request.url);\n\t\tconsole.log(url.origin, ctx.context.options.baseURL);\n\t\t/**\n\t\t * If origin is the same as baseURL or if the\n\t\t * origin is in the trustedOrigins then we\n\t\t * don't need to check the CSRF token.\n\t\t */\n\t\tif (\n\t\t\turl.origin === ctx.context.options.baseURL ||\n\t\t\tctx.context.options.trustedOrigins?.includes(url.origin)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst csrfToken = ctx.body?.csrfToken;\n\t\tconst csrfCookie = await ctx.getSignedCookie(\n\t\t\tctx.context.authCookies.csrfToken.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\tconst [token, hash] = csrfCookie?.split(\"!\") || [null, null];\n\t\tif (\n\t\t\t!csrfToken ||\n\t\t\t!csrfCookie ||\n\t\t\t!token ||\n\t\t\t!hash ||\n\t\t\tcsrfCookie !== csrfToken\n\t\t) {\n\t\t\tctx.setCookie(ctx.context.authCookies.csrfToken.name, \"\", {\n\t\t\t\tmaxAge: 0,\n\t\t\t});\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid CSRF Token\",\n\t\t\t});\n\t\t}\n\t\tconst expectedHash = await hs256(ctx.context.secret, token);\n\t\tif (hash !== expectedHash) {\n\t\t\tctx.setCookie(ctx.context.authCookies.csrfToken.name, \"\", {\n\t\t\t\tmaxAge: 0,\n\t\t\t});\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid CSRF Token\",\n\t\t\t});\n\t\t}\n\t},\n);\n","import { xchacha20poly1305 } from \"@noble/ciphers/chacha\";\nimport { bytesToHex, hexToBytes, utf8ToBytes } from \"@noble/ciphers/utils\";\nimport { managedNonce } from \"@noble/ciphers/webcrypto\";\nimport { sha256 } from \"@noble/hashes/sha256\";\n\nexport async function hs256(secretKey: string, message: string) {\n\tconst enc = new TextEncoder();\n\tconst algorithm = { name: \"HMAC\", hash: \"SHA-256\" };\n\tconst key = await crypto.subtle.importKey(\n\t\t\"raw\",\n\t\tenc.encode(secretKey),\n\t\talgorithm,\n\t\tfalse,\n\t\t[\"sign\", \"verify\"],\n\t);\n\tconst signature = await crypto.subtle.sign(\n\t\talgorithm.name,\n\t\tkey,\n\t\tenc.encode(message),\n\t);\n\treturn btoa(String.fromCharCode(...new Uint8Array(signature)));\n}\n\nexport type SymmetricEncryptOptions = {\n\tkey: string;\n\tdata: string;\n};\n\nexport const symmetricEncrypt = ({ key, data }: SymmetricEncryptOptions) => {\n\tconst keyAsBytes = sha256(key);\n\tconst dataAsBytes = utf8ToBytes(data);\n\tconst chacha = managedNonce(xchacha20poly1305)(keyAsBytes);\n\treturn bytesToHex(chacha.encrypt(dataAsBytes));\n};\n\nexport type SymmetricDecryptOptions = {\n\tkey: string;\n\tdata: string;\n};\n\nexport const symmetricDecrypt = ({ key, data }: SymmetricDecryptOptions) => {\n\tconst keyAsBytes = sha256(key);\n\tconst dataAsBytes = hexToBytes(data);\n\tconst chacha = managedNonce(xchacha20poly1305)(keyAsBytes);\n\treturn chacha.decrypt(dataAsBytes);\n};\n","import {\n\ttype Endpoint,\n\ttype EndpointResponse,\n\tcreateEndpointCreator,\n\tcreateMiddleware,\n\tcreateMiddlewareCreator,\n} from \"better-call\";\nimport type { AuthContext } from \"../init\";\nimport type { BetterAuthOptions } from \"../types/options\";\n\nexport const optionsMiddleware = createMiddleware(async () => {\n\t/**\n\t * This will be passed on the instance of\n\t * the context. Used to infer the type\n\t * here.\n\t */\n\treturn {} as AuthContext;\n});\n\nexport const createAuthMiddleware = createMiddlewareCreator({\n\tuse: [optionsMiddleware],\n});\n\nexport const createAuthEndpoint = createEndpointCreator({\n\tuse: [optionsMiddleware],\n});\n\nexport type AuthEndpoint = Endpoint<\n\t(ctx: {\n\t\toptions: BetterAuthOptions;\n\t\tbody: any;\n\t\tquery: any;\n\t\theaders: Headers;\n\t}) => Promise<EndpointResponse>\n>;\n\nexport type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;\n","import { APIError } from \"better-call\";\nimport { generateCodeVerifier } from \"oslo/oauth2\";\nimport { Argon2id } from \"oslo/password\";\nimport { z } from \"zod\";\nimport { oAuthProviderList } from \"../../social-providers\";\nimport { generateState } from \"../../utils/state\";\nimport { createAuthEndpoint } from \"../call\";\nimport { getSessionFromCtx } from \"./session\";\n\nexport const signInOAuth = createAuthEndpoint(\n\t\"/sign-in/social\",\n\t{\n\t\tmethod: \"POST\",\n\t\trequireHeaders: true,\n\t\tquery: z\n\t\t\t.object({\n\t\t\t\t/**\n\t\t\t\t * Redirect to the current URL after the\n\t\t\t\t * user has signed in.\n\t\t\t\t */\n\t\t\t\tcurrentURL: z.string().optional(),\n\t\t\t})\n\t\t\t.optional(),\n\t\tbody: z.object({\n\t\t\t/**\n\t\t\t * Callback URL to redirect to after the user has signed in.\n\t\t\t */\n\t\t\tcallbackURL: z.string().optional(),\n\t\t\t/**\n\t\t\t * OAuth2 provider to use`\n\t\t\t */\n\t\t\tprovider: z.enum(oAuthProviderList),\n\t\t}),\n\t},\n\tasync (c) => {\n\t\tconst provider = c.context.options.socialProvider?.find(\n\t\t\t(p) => p.id === c.body.provider,\n\t\t);\n\t\tif (!provider) {\n\t\t\tc.context.logger.error(\n\t\t\t\t\"Provider not found. Make sure to add the provider to your auth config\",\n\t\t\t\t{\n\t\t\t\t\tprovider: c.body.provider,\n\t\t\t\t},\n\t\t\t);\n\t\t\tthrow new APIError(\"NOT_FOUND\");\n\t\t}\n\t\tconst cookie = c.context.authCookies;\n\t\tconst currentURL = c.query?.currentURL\n\t\t\t? new URL(c.query?.currentURL)\n\t\t\t: null;\n\t\tconst state = generateState(\n\t\t\tc.body.callbackURL || currentURL?.origin || c.context.baseURL,\n\t\t\tc.query?.currentURL,\n\t\t);\n\t\ttry {\n\t\t\tawait c.setSignedCookie(\n\t\t\t\tcookie.state.name,\n\t\t\t\tstate.code,\n\t\t\t\tc.context.secret,\n\t\t\t\tcookie.state.options,\n\t\t\t);\n\t\t\tconst codeVerifier = generateCodeVerifier();\n\t\t\tawait c.setSignedCookie(\n\t\t\t\tcookie.pkCodeVerifier.name,\n\t\t\t\tcodeVerifier,\n\t\t\t\tc.context.secret,\n\t\t\t\tcookie.pkCodeVerifier.options,\n\t\t\t);\n\t\t\tconst url = provider.createAuthorizationURL({\n\t\t\t\tstate: state.state,\n\t\t\t\tcodeVerifier,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\turl: url.toString(),\n\t\t\t\tstate: state.state,\n\t\t\t\tcodeVerifier,\n\t\t\t\tredirect: true,\n\t\t\t};\n\t\t} catch (e) {\n\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\");\n\t\t}\n\t},\n);\n\nexport const signInEmail = createAuthEndpoint(\n\t\"/sign-in/email\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\temail: z.string().email(),\n\t\t\tpassword: z.string(),\n\t\t\tcallbackURL: z.string().optional(),\n\t\t\t/**\n\t\t\t * If this is true the session will only be valid for the current browser session\n\t\t\t * @default false\n\t\t\t */\n\t\t\tdontRememberMe: z.boolean().default(false).optional(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tif (!ctx.context.options?.emailAndPassword?.enabled) {\n\t\t\tctx.context.logger.error(\"Email and password is not enabled\");\n\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\tmessage: \"Email and password is not enabled\",\n\t\t\t});\n\t\t}\n\t\tconst currentSession = await getSessionFromCtx(ctx);\n\t\tif (currentSession) {\n\t\t\treturn ctx.json({\n\t\t\t\tuser: currentSession.user,\n\t\t\t\tsession: currentSession.session,\n\t\t\t\tredirect: !!ctx.body.callbackURL,\n\t\t\t\turl: ctx.body.callbackURL,\n\t\t\t});\n\t\t}\n\t\tconst { email, password } = ctx.body;\n\t\tconst argon2id = new Argon2id();\n\t\tconst user = await ctx.context.internalAdapter.findUserByEmail(email);\n\t\tif (!user) {\n\t\t\tawait argon2id.hash(password);\n\t\t\tctx.context.logger.error(\"User not found\", { email });\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid email or password\",\n\t\t\t});\n\t\t}\n\t\tconst credentialAccount = user.accounts.find(\n\t\t\t(a) => a.providerId === \"credential\",\n\t\t);\n\t\tif (!credentialAccount) {\n\t\t\tctx.context.logger.error(\"Credential account not found\", { email });\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid email or password\",\n\t\t\t});\n\t\t}\n\t\tconst currentPassword = credentialAccount?.password;\n\t\tif (!currentPassword) {\n\t\t\tctx.context.logger.error(\"Password not found\", { email });\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Unexpected error\",\n\t\t\t});\n\t\t}\n\t\tconst validPassword = await argon2id.verify(currentPassword, password);\n\t\tif (!validPassword) {\n\t\t\tctx.context.logger.error(\"Invalid password\");\n\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\tmessage: \"Invalid email or password\",\n\t\t\t});\n\t\t}\n\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\tuser.user.id,\n\t\t\tctx.request,\n\t\t);\n\t\tawait ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tsession.id,\n\t\t\tctx.context.secret,\n\t\t\tctx.body.dontRememberMe\n\t\t\t\t? {\n\t\t\t\t\t\t...ctx.context.authCookies.sessionToken.options,\n\t\t\t\t\t\tmaxAge: undefined,\n\t\t\t\t\t}\n\t\t\t\t: ctx.context.authCookies.sessionToken.options,\n\t\t);\n\t\treturn ctx.json({\n\t\t\tuser: user.user,\n\t\t\tsession,\n\t\t\tredirect: !!ctx.body.callbackURL,\n\t\t\turl: ctx.body.callbackURL,\n\t\t});\n\t},\n);\n","import { OAuth2Tokens } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { parseJWT } from \"oslo/jwt\";\nimport { betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\nimport { getRedirectURI } from \"./utils\";\nexport interface AppleProfile {\n\t/**\n\t * The subject registered claim identifies the principal that’s the subject\n\t * of the identity token. Because this token is for your app, the value is\n\t * the unique identifier for the user.\n\t */\n\tsub: string;\n\t/**\n\t * A String value representing the user's email address.\n\t * The email address is either the user's real email address or the proxy\n\t * address, depending on their status private email relay service.\n\t */\n\temail: string;\n\t/**\n\t * A string or Boolean value that indicates whether the service verifies\n\t * the email. The value can either be a string (\"true\" or \"false\") or a\n\t * Boolean (true or false). The system may not verify email addresses for\n\t * Sign in with Apple at Work & School users, and this claim is \"false\" or\n\t * false for those users.\n\t */\n\temail_verified: true | \"true\";\n\t/**\n\t * A string or Boolean value that indicates whether the email that the user\n\t * shares is the proxy address. The value can either be a string (\"true\" or\n\t * \"false\") or a Boolean (true or false).\n\t */\n\tis_private_email: boolean;\n\t/**\n\t * An Integer value that indicates whether the user appears to be a real\n\t * person. Use the value of this claim to mitigate fraud. The possible\n\t * values are: 0 (or Unsupported), 1 (or Unknown), 2 (or LikelyReal). For\n\t * more information, see ASUserDetectionStatus. This claim is present only\n\t * in iOS 14 and later, macOS 11 and later, watchOS 7 and later, tvOS 14\n\t * and later. The claim isn’t present or supported for web-based apps.\n\t */\n\treal_user_status: number;\n\t/**\n\t * The user’s full name in the format provided during the authorization\n\t * process.\n\t */\n\tname: string;\n}\n\nexport interface AppleOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const apple = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: AppleOptions) => {\n\tconst tokenEndpoint = \"https://appleid.apple.com/auth/token\";\n\tredirectURI = getRedirectURI(\"apple\", redirectURI);\n\treturn {\n\t\tid: \"apple\",\n\t\tname: \"Apple\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scope = scopes || [\"email\", \"name\", \"openid\"];\n\t\t\treturn new URL(\n\t\t\t\t`https://appleid.apple.com/auth/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectURI}&scope=${_scope.join(\n\t\t\t\t\t\" \",\n\t\t\t\t)}&state=${state}`,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code) => {\n\t\t\tconst data = await betterFetch<OAuth2Tokens>(tokenEndpoint, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: new URLSearchParams({\n\t\t\t\t\tclient_id: clientId,\n\t\t\t\t\tclient_secret: clientSecret,\n\t\t\t\t\tgrant_type: \"authorization_code\",\n\t\t\t\t\tcode,\n\t\t\t\t}),\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (data.error) {\n\t\t\t\tthrow new BetterAuthError(data.error?.message || \"\");\n\t\t\t}\n\t\t\treturn data.data;\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tconst data = parseJWT(token.idToken())?.payload as AppleProfile | null;\n\t\t\tif (!data) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: data.sub,\n\t\t\t\t\tname: data.name,\n\t\t\t\t\temail: data.email,\n\t\t\t\t\temailVerified: data.email_verified === \"true\",\n\t\t\t\t},\n\t\t\t\tdata,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<AppleProfile>;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\tconst env: any = typeof process !== \"undefined\" ? process.env : {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { getBaseURL } from \"../utils/base-url\";\n\nexport function getRedirectURI(providerId: string, redirectURI?: string) {\n\treturn redirectURI || `${getBaseURL()}/api/auth/callback/${providerId}`;\n}\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Discord } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface DiscordProfile extends Record<string, any> {\n\t/** the user's id (i.e. the numerical snowflake) */\n\tid: string;\n\t/** the user's username, not unique across the platform */\n\tusername: string;\n\t/** the user's Discord-tag */\n\tdiscriminator: string;\n\t/** the user's display name, if it is set */\n\tglobal_name: string | null;\n\t/**\n\t * the user's avatar hash:\n\t * https://discord.com/developers/docs/reference#image-formatting\n\t */\n\tavatar: string | null;\n\t/** whether the user belongs to an OAuth2 application */\n\tbot?: boolean;\n\t/**\n\t * whether the user is an Official Discord System user (part of the urgent\n\t * message system)\n\t */\n\tsystem?: boolean;\n\t/** whether the user has two factor enabled on their account */\n\tmfa_enabled: boolean;\n\t/**\n\t * the user's banner hash:\n\t * https://discord.com/developers/docs/reference#image-formatting\n\t */\n\tbanner: string | null;\n\n\t/** the user's banner color encoded as an integer representation of hexadecimal color code */\n\taccent_color: number | null;\n\n\t/**\n\t * the user's chosen language option:\n\t * https://discord.com/developers/docs/reference#locales\n\t */\n\tlocale: string;\n\t/** whether the email on this account has been verified */\n\tverified: boolean;\n\t/** the user's email */\n\temail: string;\n\t/**\n\t * the flags on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-user-flags\n\t */\n\tflags: number;\n\t/**\n\t * the type of Nitro subscription on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-premium-types\n\t */\n\tpremium_type: number;\n\t/**\n\t * the public flags on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-user-flags\n\t */\n\tpublic_flags: number;\n\t/** undocumented field; corresponds to the user's custom nickname */\n\tdisplay_name: string | null;\n\t/**\n\t * undocumented field; corresponds to the Discord feature where you can e.g.\n\t * put your avatar inside of an ice cube\n\t */\n\tavatar_decoration: string | null;\n\t/**\n\t * undocumented field; corresponds to the premium feature where you can\n\t * select a custom banner color\n\t */\n\tbanner_color: string | null;\n\t/** undocumented field; the CDN URL of their profile picture */\n\timage_url: string;\n}\n\nexport interface DiscordOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const discord = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: DiscordOptions) => {\n\tconst discordArctic = new Discord(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"discord\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"discord\",\n\t\tname: \"Discord\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scope = scopes || [\"email\"];\n\t\t\treturn discordArctic.createAuthorizationURL(state, _scope);\n\t\t},\n\t\tvalidateAuthorizationCode: discordArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<DiscordProfile>(\n\t\t\t\t\"https://discord.com/api/users/@me\",\n\t\t\t\t{\n\t\t\t\t\tauth: {\n\t\t\t\t\t\ttype: \"Bearer\",\n\t\t\t\t\t\ttoken: token.accessToken,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.display_name || profile.username || \"\",\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\temailVerified: profile.verified,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<DiscordProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Facebook } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface FacebookProfile {\n\tid: string;\n\tname: string;\n\temail: string;\n\temail_verified: boolean;\n\tpicture: {\n\t\tdata: {\n\t\t\theight: number;\n\t\t\tis_silhouette: boolean;\n\t\t\turl: string;\n\t\t\twidth: number;\n\t\t};\n\t};\n}\nexport interface FacebookOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\nexport const facebook = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: FacebookOptions) => {\n\tconst facebookArctic = new Facebook(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"facebook\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"facebook\",\n\t\tname: \"Facebook\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"email\", \"public_profile\"];\n\t\t\treturn facebookArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: facebookArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<FacebookProfile>(\n\t\t\t\t\"https://graph.facebook.com/me\",\n\t\t\t\t{\n\t\t\t\t\tauth: {\n\t\t\t\t\t\ttype: \"Bearer\",\n\t\t\t\t\t\ttoken: token.accessToken,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\temailVerified: profile.email_verified,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<FacebookProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { GitHub } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface GithubProfile {\n\tlogin: string;\n\tid: string;\n\tnode_id: string;\n\tavatar_url: string;\n\tgravatar_id: string;\n\turl: string;\n\thtml_url: string;\n\tfollowers_url: string;\n\tfollowing_url: string;\n\tgists_url: string;\n\tstarred_url: string;\n\tsubscriptions_url: string;\n\torganizations_url: string;\n\trepos_url: string;\n\tevents_url: string;\n\treceived_events_url: string;\n\ttype: string;\n\tsite_admin: boolean;\n\tname: string;\n\tcompany: string;\n\tblog: string;\n\tlocation: string;\n\temail: string;\n\thireable: boolean;\n\tbio: string;\n\ttwitter_username: string;\n\tpublic_repos: string;\n\tpublic_gists: string;\n\tfollowers: string;\n\tfollowing: string;\n\tcreated_at: string;\n\tupdated_at: string;\n\tprivate_gists: string;\n\ttotal_private_repos: string;\n\towned_private_repos: string;\n\tdisk_usage: string;\n\tcollaborators: string;\n\ttwo_factor_authentication: boolean;\n\tplan: {\n\t\tname: string;\n\t\tspace: string;\n\t\tprivate_repos: string;\n\t\tcollaborators: string;\n\t};\n\tfirst_name: string;\n\tlast_name: string;\n}\n\nexport interface GithubOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\nexport const github = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: GithubOptions) => {\n\tconst githubArctic = new GitHub(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"github\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"github\",\n\t\tname: \"Github\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"user:email\"];\n\t\t\treturn githubArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: githubArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<GithubProfile>(\n\t\t\t\t\"https://api.github.com/user\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tlet emailVerified = false;\n\t\t\tif (!profile.email) {\n\t\t\t\tconst { data, error } = await betterFetch<\n\t\t\t\t\t{\n\t\t\t\t\t\temail: string;\n\t\t\t\t\t\tprimary: boolean;\n\t\t\t\t\t\tverified: boolean;\n\t\t\t\t\t\tvisibility: \"public\" | \"private\";\n\t\t\t\t\t}[]\n\t\t\t\t>(\"https://api.github.com/user/emails\", {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t\t\"User-Agent\": \"better-auth\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (!error) {\n\t\t\t\t\tprofile.email = (data.find((e) => e.primary) ?? data[0])\n\t\t\t\t\t\t?.email as string;\n\t\t\t\t\temailVerified =\n\t\t\t\t\t\tdata.find((e) => e.email === profile.email)?.verified ?? false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.avatar_url,\n\t\t\t\t\temailVerified,\n\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<GithubProfile>;\n};\n","import { Google } from \"arctic\";\nimport { parseJWT } from \"oslo/jwt\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport interface GoogleProfile {\n\taud: string;\n\tazp: string;\n\temail: string;\n\temail_verified: boolean;\n\texp: number;\n\t/**\n\t * The family name of the user, or last name in most\n\t * Western languages.\n\t */\n\tfamily_name: string;\n\t/**\n\t * The given name of the user, or first name in most\n\t * Western languages.\n\t */\n\tgiven_name: string;\n\thd?: string;\n\tiat: number;\n\tiss: string;\n\tjti?: string;\n\tlocale?: string;\n\tname: string;\n\tnbf?: number;\n\tpicture: string;\n\tsub: string;\n}\n\nexport interface GoogleOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const google = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: GoogleOptions) => {\n\tconst googleArctic = new Google(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"google\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"google\",\n\t\tname: \"Google\",\n\t\tcreateAuthorizationURL({ state, scopes, codeVerifier }) {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Google\");\n\t\t\t}\n\t\t\tconst _scopes = scopes || [\"email\", \"profile\"];\n\t\t\treturn googleArctic.createAuthorizationURL(state, codeVerifier, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code, codeVerifier) => {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Google\");\n\t\t\t}\n\t\t\treturn googleArctic.validateAuthorizationCode(code, codeVerifier);\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tif (!token.idToken) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst user = parseJWT(token.idToken())?.payload as GoogleProfile;\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: user.sub,\n\t\t\t\t\tname: user.name,\n\t\t\t\t\temail: user.email,\n\t\t\t\t\timage: user.picture,\n\t\t\t\t\temailVerified: user.email_verified,\n\t\t\t\t},\n\t\t\t\tdata: user,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<GoogleProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Spotify } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface SpotifyProfile {\n\tid: string;\n\tdisplay_name: string;\n\temail: string;\n\timages: {\n\t\turl: string;\n\t}[];\n}\n\nexport interface SpotifyOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const spotify = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: SpotifyOptions) => {\n\tconst spotifyArctic = new Spotify(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"spotify\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"spotify\",\n\t\tname: \"Spotify\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"user-read-email\"];\n\t\t\treturn spotifyArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: spotifyArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<SpotifyProfile>(\n\t\t\t\t\"https://api.spotify.com/v1/me\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.display_name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.images[0]?.url,\n\t\t\t\t\temailVerified: false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<SpotifyProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Twitch } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface TwitchProfile {\n\t/**\n\t * The sub of the user\n\t */\n\tsub: string;\n\t/**\n\t * The preferred username of the user\n\t */\n\tpreferred_username: string;\n\t/**\n\t * The email of the user\n\t */\n\temail: string;\n\t/**\n\t * The picture of the user\n\t */\n\tpicture: string;\n}\n\nexport interface TwitchOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const twitch = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: TwitchOptions) => {\n\tconst twitchArctic = new Twitch(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"twitch\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"twitch\",\n\t\tname: \"Twitch\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"activity:write\", \"read\"];\n\t\t\treturn twitchArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: twitchArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<TwitchProfile>(\n\t\t\t\t\"https://api.twitch.tv/helix/users\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.sub,\n\t\t\t\t\tname: profile.preferred_username,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.picture,\n\t\t\t\t\temailVerified: false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<TwitchProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Twitter } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport interface TwitterProfile {\n\tdata: {\n\t\t/**\n\t\t * Unique identifier of this user. This is returned as a string in order to avoid complications with languages and tools\n\t\t * that cannot handle large integers.\n\t\t */\n\t\tid: string;\n\t\t/** The friendly name of this user, as shown on their profile. */\n\t\tname: string;\n\t\t/** @note Email is currently unsupported by Twitter. */\n\t\temail?: string;\n\t\t/** The Twitter handle (screen name) of this user. */\n\t\tusername: string;\n\t\t/**\n\t\t * The location specified in the user's profile, if the user provided one.\n\t\t * As this is a freeform value, it may not indicate a valid location, but it may be fuzzily evaluated when performing searches with location queries.\n\t\t *\n\t\t * To return this field, add `user.fields=location` in the authorization request's query parameter.\n\t\t */\n\t\tlocation?: string;\n\t\t/**\n\t\t * This object and its children fields contain details about text that has a special meaning in the user's description.\n\t\t *\n\t\t *To return this field, add `user.fields=entities` in the authorization request's query parameter.\n\t\t */\n\t\tentities?: {\n\t\t\t/** Contains details about the user's profile website. */\n\t\t\turl: {\n\t\t\t\t/** Contains details about the user's profile website. */\n\t\t\t\turls: Array<{\n\t\t\t\t\t/** The start position (zero-based) of the recognized user's profile website. All start indices are inclusive. */\n\t\t\t\t\tstart: number;\n\t\t\t\t\t/** The end position (zero-based) of the recognized user's profile website. This end index is exclusive. */\n\t\t\t\t\tend: number;\n\t\t\t\t\t/** The URL in the format entered by the user. */\n\t\t\t\t\turl: string;\n\t\t\t\t\t/** The fully resolved URL. */\n\t\t\t\t\texpanded_url: string;\n\t\t\t\t\t/** The URL as displayed in the user's profile. */\n\t\t\t\t\tdisplay_url: string;\n\t\t\t\t}>;\n\t\t\t};\n\t\t\t/** Contains details about URLs, Hashtags, Cashtags, or mentions located within a user's description. */\n\t\t\tdescription: {\n\t\t\t\thashtags: Array<{\n\t\t\t\t\tstart: number;\n\t\t\t\t\tend: number;\n\t\t\t\t\ttag: string;\n\t\t\t\t}>;\n\t\t\t};\n\t\t};\n\t\t/**\n\t\t * Indicate if this user is a verified Twitter user.\n\t\t *\n\t\t * To return this field, add `user.fields=verified` in the authorization request's query parameter.\n\t\t */\n\t\tverified?: boolean;\n\t\t/**\n\t\t * The text of this user's profile description (also known as bio), if the user provided one.\n\t\t *\n\t\t * To return this field, add `user.fields=description` in the authorization request's query parameter.\n\t\t */\n\t\tdescription?: string;\n\t\t/**\n\t\t * The URL specified in the user's profile, if present.\n\t\t *\n\t\t * To return this field, add `user.fields=url` in the authorization request's query parameter.\n\t\t */\n\t\turl?: string;\n\t\t/** The URL to the profile image for this user, as shown on the user's profile. */\n\t\tprofile_image_url?: string;\n\t\tprotected?: boolean;\n\t\t/**\n\t\t * Unique identifier of this user's pinned Tweet.\n\t\t *\n\t\t * You can obtain the expanded object in `includes.tweets` by adding `expansions=pinned_tweet_id` in the authorization request's query parameter.\n\t\t */\n\t\tpinned_tweet_id?: string;\n\t\tcreated_at?: string;\n\t};\n\tincludes?: {\n\t\ttweets?: Array<{\n\t\t\tid: string;\n\t\t\ttext: string;\n\t\t}>;\n\t};\n\t[claims: string]: unknown;\n}\n\nexport interface TwitterOption {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const twitter = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: TwitterOption) => {\n\tconst twitterArctic = new Twitter(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"twitter\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"twitter\",\n\t\tname: \"Twitter\",\n\t\tcreateAuthorizationURL(data) {\n\t\t\tconst _scopes = data.scopes || [\"account_info.read\"];\n\t\t\treturn twitterArctic.createAuthorizationURL(\n\t\t\t\tdata.state,\n\t\t\t\tdata.codeVerifier,\n\t\t\t\t_scopes,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code, codeVerifier) => {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Twitter\");\n\t\t\t}\n\t\t\treturn twitterArctic.validateAuthorizationCode(code, codeVerifier);\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<TwitterProfile>(\n\t\t\t\t\"https://api.x.com/2/users/me?user.fields=profile_image_url\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (!profile.data.email) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.data.id,\n\t\t\t\t\tname: profile.data.name,\n\t\t\t\t\temail: profile.data.email,\n\t\t\t\t\timage: profile.data.profile_image_url,\n\t\t\t\t\temailVerified: profile.data.verified || false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<TwitterProfile>;\n};\n","import type { User } from \"../adapters/schema\";\nimport type { oAuthProviderList } from \"../social-providers\";\nimport type { LiteralString } from \"./helper\";\nimport { OAuth2Tokens } from \"arctic\";\n\nexport interface OAuthProvider<\n\tT extends Record<string, any> = Record<string, any>,\n> {\n\tid: LiteralString;\n\tcreateAuthorizationURL: (data: {\n\t\tstate: string;\n\t\tcodeVerifier: string;\n\t\tscopes?: string[];\n\t}) => URL;\n\tname: string;\n\tvalidateAuthorizationCode: (\n\t\tcode: string,\n\t\tcodeVerifier?: string,\n\t) => Promise<OAuth2Tokens>;\n\tgetUserInfo: (token: OAuth2Tokens) => Promise<{\n\t\tuser: Omit<User, \"createdAt\" | \"updatedAt\">;\n\t\tdata: T;\n\t} | null>;\n\trefreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;\n\trevokeToken?: (token: string) => Promise<void>;\n}\n\nexport type OAuthProviderList = typeof oAuthProviderList;\n","import { apple } from \"./apple\";\nimport { discord } from \"./discord\";\nimport { facebook } from \"./facebook\";\nimport { github } from \"./github\";\nimport { google } from \"./google\";\nimport { spotify } from \"./spotify\";\nimport { twitch } from \"./twitch\";\nimport { twitter } from \"./twitter\";\n\nexport const oAuthProviders = {\n\tapple,\n\tdiscord,\n\tfacebook,\n\tgithub,\n\tgoogle,\n\tspotify,\n\ttwitch,\n\ttwitter,\n};\n\nexport const oAuthProviderList = Object.keys(oAuthProviders) as [\n\t\"github\",\n\t...(keyof typeof oAuthProviders)[],\n];\n\nexport * from \"./github\";\nexport * from \"./google\";\nexport * from \"./apple\";\nexport * from \"./discord\";\nexport * from \"./spotify\";\nexport * from \"./twitch\";\nexport * from \"./facebook\";\nexport * from \"./twitter\";\nexport * from \"../types/provider\";\n","import { generateState as generateStateOAuth } from \"oslo/oauth2\";\n\nexport function generateState(callbackURL?: string, currentURL?: string) {\n\tconst code = generateStateOAuth();\n\tconst state = `${code}!${callbackURL}!${currentURL}`;\n\treturn { state, code };\n}\n\nexport function parseState(state: string) {\n\tconst [code, callbackURL, currentURL] = state.split(\"!\");\n\treturn { code, callbackURL, currentURL };\n}\n","import type { Context } from \"better-call\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const getSession = createAuthEndpoint(\n\t\"/session\",\n\t{\n\t\tmethod: \"GET\",\n\t\trequireHeaders: true,\n\t},\n\tasync (ctx) => {\n\t\tconst sessionCookieToken = await ctx.getSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\tif (!sessionCookieToken) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 401,\n\t\t\t});\n\t\t}\n\t\tconst session =\n\t\t\tawait ctx.context.internalAdapter.findSession(sessionCookieToken);\n\t\tif (!session || session.session.expiresAt < new Date()) {\n\t\t\tctx.setSignedCookie(\n\t\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\t\t\"\",\n\t\t\t\tctx.context.secret,\n\t\t\t\t{\n\t\t\t\t\tmaxAge: 0,\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 401,\n\t\t\t});\n\t\t}\n\t\tconst updatedSession = await ctx.context.internalAdapter.updateSession(\n\t\t\tsession.session,\n\t\t);\n\n\t\tawait ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tupdatedSession.id,\n\t\t\tctx.context.secret,\n\t\t\t{\n\t\t\t\t...ctx.context.authCookies.sessionToken.options,\n\t\t\t\tmaxAge: updatedSession.expiresAt.valueOf() - Date.now(),\n\t\t\t},\n\t\t);\n\t\treturn ctx.json({\n\t\t\tsession: updatedSession,\n\t\t\tuser: session.user,\n\t\t});\n\t},\n);\n\nexport const getSessionFromCtx = async (ctx: Context<any, any>) => {\n\tconst session = await getSession({\n\t\t...ctx,\n\t\t//@ts-expect-error: By default since this request context comes from a router it'll have a `router` flag which force it to be a request object\n\t\t_flag: undefined,\n\t});\n\treturn session;\n};\n","import { APIError } from \"better-call\";\nimport { z } from \"zod\";\nimport { userSchema } from \"../../adapters/schema\";\nimport { HIDE_ON_CLIENT_METADATA } from \"../../client/client-utils\";\nimport { generateId } from \"../../utils/id\";\nimport { parseState } from \"../../utils/state\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const callbackOAuth = createAuthEndpoint(\n\t\"/callback/:id\",\n\t{\n\t\tmethod: \"GET\",\n\t\tquery: z.object({\n\t\t\tstate: z.string(),\n\t\t\tcode: z.string(),\n\t\t\tcode_verifier: z.string().optional(),\n\t\t}),\n\t\tmetadata: HIDE_ON_CLIENT_METADATA,\n\t},\n\tasync (c) => {\n\t\tconst provider = c.context.options.socialProvider?.find(\n\t\t\t(p) => p.id === c.params.id,\n\t\t);\n\t\tif (!provider) {\n\t\t\tc.context.logger.error(\n\t\t\t\t\"Oauth provider with id\",\n\t\t\t\tc.params.id,\n\t\t\t\t\"not found\",\n\t\t\t);\n\t\t\tthrow new APIError(\"NOT_FOUND\");\n\t\t}\n\t\tconst tokens = await provider.validateAuthorizationCode(\n\t\t\tc.query.code,\n\t\t\tc.query.code_verifier || \"\",\n\t\t);\n\t\tif (!tokens) {\n\t\t\tc.context.logger.error(\"Code verification failed\");\n\t\t\tthrow new APIError(\"UNAUTHORIZED\");\n\t\t}\n\t\tconst user = await provider.getUserInfo(tokens).then((res) => res?.user);\n\t\tconst id = generateId();\n\t\tconst data = userSchema.safeParse({\n\t\t\t...user,\n\t\t\tid,\n\t\t});\n\t\tconst { callbackURL, currentURL } = parseState(c.query.state);\n\t\tif (!user || data.success === false) {\n\t\t\tif (currentURL) {\n\t\t\t\tthrow c.redirect(`${currentURL}?error=oauth_validation_failed`);\n\t\t\t} else {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\");\n\t\t\t}\n\t\t}\n\t\tif (!callbackURL) {\n\t\t\tc.context.logger.error(\"Callback URL not found\");\n\t\t\tthrow new APIError(\"FORBIDDEN\");\n\t\t}\n\t\t//find user in db\n\t\tconst dbUser = await c.context.internalAdapter.findUserByEmail(user.email);\n\t\tconst userId = dbUser?.user.id;\n\t\tif (dbUser) {\n\t\t\t//check if user has already linked this provider\n\t\t\tconst hasBeenLinked = dbUser.accounts.find(\n\t\t\t\t(a) => a.providerId === provider.id,\n\t\t\t);\n\t\t\tif (!hasBeenLinked && !user.emailVerified) {\n\t\t\t\tc.context.logger.error(\"User already exists\");\n\t\t\t\tconst url = new URL(currentURL || callbackURL);\n\t\t\t\turl.searchParams.set(\"error\", \"user_already_exists\");\n\t\t\t\tthrow c.redirect(url.toString());\n\t\t\t}\n\n\t\t\tif (!hasBeenLinked && user.emailVerified) {\n\t\t\t\tawait c.context.internalAdapter.linkAccount({\n\t\t\t\t\tproviderId: provider.id,\n\t\t\t\t\taccountId: user.id,\n\t\t\t\t\tid: `${provider.id}:${user.id}`,\n\t\t\t\t\tuserId: dbUser.user.id,\n\t\t\t\t\t...tokens,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tawait c.context.internalAdapter.createOAuthUser(data.data, {\n\t\t\t\t\t...tokens,\n\t\t\t\t\tid: `${provider.id}:${user.id}`,\n\t\t\t\t\tproviderId: provider.id,\n\t\t\t\t\taccountId: user.id,\n\t\t\t\t\tuserId: id,\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\tconst url = new URL(currentURL || callbackURL);\n\t\t\t\turl.searchParams.set(\"error\", \"unable_to_create_user\");\n\t\t\t\tc.setHeader(\"Location\", url.toString());\n\t\t\t\tthrow c.redirect(url.toString());\n\t\t\t}\n\t\t}\n\t\t//this should never happen\n\t\tif (!userId && !id)\n\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\tmessage: \"Unable to create user\",\n\t\t\t});\n\t\t//create session\n\t\tconst session = await c.context.internalAdapter.createSession(\n\t\t\tuserId || id,\n\t\t\tc.request,\n\t\t);\n\t\ttry {\n\t\t\tawait c.setSignedCookie(\n\t\t\t\tc.context.authCookies.sessionToken.name,\n\t\t\t\tsession.id,\n\t\t\t\tc.context.secret,\n\t\t\t\tc.context.authCookies.sessionToken.options,\n\t\t\t);\n\t\t} catch (e) {\n\t\t\tc.context.logger.error(\"Unable to set session cookie\", e);\n\t\t\tconst url = new URL(currentURL || callbackURL);\n\t\t\turl.searchParams.set(\"error\", \"unable_to_create_session\");\n\t\t\tthrow c.redirect(url.toString());\n\t\t}\n\t\tthrow c.redirect(callbackURL);\n\t},\n);\n","export const HIDE_ON_CLIENT_METADATA = {\n\tonClient: \"hide\" as const,\n};\n","import { alphabet, generateRandomString } from \"oslo/crypto\";\nexport const generateId = () => {\n\treturn generateRandomString(36, alphabet(\"a-z\", \"0-9\"));\n};\n","import { z } from \"zod\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const signOut = createAuthEndpoint(\n\t\"/sign-out\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z\n\t\t\t.object({\n\t\t\t\tcallbackURL: z.string().optional(),\n\t\t\t})\n\t\t\t.optional(),\n\t},\n\tasync (ctx) => {\n\t\tconst sessionCookieToken = await ctx.getSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\tif (!sessionCookieToken) {\n\t\t\treturn ctx.json(null);\n\t\t}\n\t\tawait ctx.context.internalAdapter.deleteSession(sessionCookieToken);\n\t\tctx.setCookie(ctx.context.authCookies.sessionToken.name, \"\", {\n\t\t\tmaxAge: 0,\n\t\t});\n\t\treturn ctx.json(null, {\n\t\t\tbody: {\n\t\t\t\tredirect: !!ctx.body?.callbackURL,\n\t\t\t\turl: ctx.body?.callbackURL,\n\t\t\t},\n\t\t});\n\t},\n);\n","import { TimeSpan } from \"oslo\";\nimport { createJWT } from \"oslo/jwt\";\nimport { validateJWT } from \"oslo/jwt\";\nimport { Argon2id } from \"oslo/password\";\nimport { z } from \"zod\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const forgetPassword = createAuthEndpoint(\n\t\"/forget-password\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\t/**\n\t\t\t * The email address of the user to send a password reset email to.\n\t\t\t */\n\t\t\temail: z.string().email(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tif (!ctx.context.options.emailAndPassword?.sendResetPasswordToken) {\n\t\t\tctx.context.logger.error(\n\t\t\t\t\"Reset password isn't enabled.Please pass an emailAndPassword.sendResetPasswordToken function to your auth config!\",\n\t\t\t);\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tstatusText: \"RESET_PASSWORD_EMAIL_NOT_SENT\",\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Reset password isn't enabled\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tconst { email } = ctx.body;\n\t\tconst user = await ctx.context.internalAdapter.findUserByEmail(email);\n\t\tif (!user) {\n\t\t\treturn ctx.json(\n\t\t\t\t{\n\t\t\t\t\terror: \"User not found\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"USER_NOT_FOUND\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tconst token = await createJWT(\n\t\t\t\"HS256\",\n\t\t\tBuffer.from(ctx.context.secret),\n\t\t\t{\n\t\t\t\temail: user.user.email,\n\t\t\t},\n\t\t\t{\n\t\t\t\texpiresIn: new TimeSpan(1, \"h\"),\n\t\t\t\tissuer: \"better-auth\",\n\t\t\t\tsubject: \"forget-password\",\n\t\t\t\taudiences: [user.user.email],\n\t\t\t\tincludeIssuedTimestamp: true,\n\t\t\t},\n\t\t);\n\t\tawait ctx.context.options.emailAndPassword.sendResetPasswordToken(\n\t\t\ttoken,\n\t\t\tuser.user,\n\t\t);\n\t\treturn ctx.json({\n\t\t\tstatus: true,\n\t\t});\n\t},\n);\n\nexport const resetPassword = createAuthEndpoint(\n\t\"/reset-password\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\ttoken: z.string(),\n\t\t\tnewPassword: z.string(),\n\t\t\tcallbackURL: z.string().optional(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tconst { token, newPassword } = ctx.body;\n\t\ttry {\n\t\t\tconst jwt = await validateJWT(\n\t\t\t\t\"HS256\",\n\t\t\t\tBuffer.from(ctx.context.secret),\n\t\t\t\ttoken,\n\t\t\t);\n\t\t\tconst email = z\n\t\t\t\t.string()\n\t\t\t\t.email()\n\t\t\t\t.parse((jwt.payload as { email: string }).email);\n\t\t\tconst user = await ctx.context.internalAdapter.findUserByEmail(email);\n\t\t\tif (!user) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"USER_NOT_FOUND\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (\n\t\t\t\tnewPassword.length <\n\t\t\t\t\t(ctx.context.options.emailAndPassword?.minPasswordLength || 8) ||\n\t\t\t\tnewPassword.length >\n\t\t\t\t\t(ctx.context.options.emailAndPassword?.maxPasswordLength || 32)\n\t\t\t) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"INVALID_PASSWORD_LENGTH\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"Password length must be between 8 and 32\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst argon2id = new Argon2id();\n\t\t\tconst hashedPassword = await argon2id.hash(newPassword);\n\t\t\tconst updatedUser = await ctx.context.internalAdapter.updatePassword(\n\t\t\t\tuser.user.id,\n\t\t\t\thashedPassword,\n\t\t\t);\n\t\t\tif (!updatedUser) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 500,\n\t\t\t\t\tstatusText: \"INTERNAL_SERVER_ERROR\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"Internal server error\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn ctx.json({\n\t\t\t\tstatus: true,\n\t\t\t\turl: ctx.body.callbackURL,\n\t\t\t\tredirect: !!ctx.body.callbackURL,\n\t\t\t});\n\t\t} catch (e) {\n\t\t\tconsole.log(e);\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tstatusText: \"INVALID_TOKEN\",\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Invalid token\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t},\n);\n","import { TimeSpan } from \"oslo\";\nimport { createJWT, validateJWT } from \"oslo/jwt\";\nimport { z } from \"zod\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const sendVerificationEmail = createAuthEndpoint(\n\t\"/send-verification-email\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\temail: z.string().email(),\n\t\t\tcallbackURL: z.string().optional(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tif (!ctx.context.options.emailAndPassword?.sendVerificationEmail) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tstatusText: \"VERIFICATION_EMAIL_NOT_SENT\",\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Verification email isn't enabled\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tconst { email } = ctx.body;\n\t\tconst token = await createJWT(\n\t\t\t\"HS256\",\n\t\t\tBuffer.from(ctx.context.secret),\n\t\t\t{\n\t\t\t\temail: email.toLowerCase(),\n\t\t\t},\n\t\t\t{\n\t\t\t\texpiresIn: new TimeSpan(1, \"h\"),\n\t\t\t\tissuer: \"better-auth\",\n\t\t\t\tsubject: \"verify-email\",\n\t\t\t\taudiences: [email],\n\t\t\t\tincludeIssuedTimestamp: true,\n\t\t\t},\n\t\t);\n\t\tconst url = `${ctx.context.baseURL}/verify-email?token=${token}?callbackURL=${ctx.body.callbackURL}`;\n\t\tawait ctx.context.options.emailAndPassword.sendVerificationEmail(\n\t\t\temail,\n\t\t\turl,\n\t\t);\n\t\treturn ctx.json({\n\t\t\tstatus: true,\n\t\t});\n\t},\n);\n\nexport const verifyEmail = createAuthEndpoint(\n\t\"/verify-email\",\n\t{\n\t\tmethod: \"GET\",\n\t\tquery: z.object({\n\t\t\ttoken: z.string(),\n\t\t\tcallbackURL: z.string(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tconst { token } = ctx.query;\n\t\ttry {\n\t\t\tconst jwt = await validateJWT(\n\t\t\t\t\"HS256\",\n\t\t\t\tBuffer.from(ctx.context.secret),\n\t\t\t\ttoken,\n\t\t\t);\n\t\t\tconst schema = z.object({\n\t\t\t\temail: z.string().email(),\n\t\t\t});\n\t\t\tconst parsed = schema.parse(jwt.payload);\n\t\t\tconst user = await ctx.context.internalAdapter.findUserByEmail(\n\t\t\t\tparsed.email,\n\t\t\t);\n\t\t\tif (!user) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"USER_NOT_FOUND\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst account = user.accounts.find((a) => a.providerId === \"credential\");\n\t\t\tif (!account) {\n\t\t\t\treturn ctx.json(null, {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\tstatusText: \"ACCOUNT_NOT_FOUND\",\n\t\t\t\t\tbody: {\n\t\t\t\t\t\tmessage: \"Account not found\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\tawait ctx.context.internalAdapter.updateUserByEmail(parsed.email, {\n\t\t\t\temailVerified: true,\n\t\t\t});\n\t\t\tif (ctx.query.callbackURL) {\n\t\t\t\tthrow ctx.redirect(ctx.query.callbackURL);\n\t\t\t}\n\t\t\treturn ctx.json({\n\t\t\t\tstatus: true,\n\t\t\t});\n\t\t} catch (e) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tstatusText: \"INVALID_TOKEN\",\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Invalid token\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t},\n);\n","import { alphabet, generateRandomString } from \"oslo/crypto\";\nimport { HIDE_ON_CLIENT_METADATA } from \"../../client/client-utils\";\nimport { hs256 } from \"../../crypto\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const getCSRFToken = createAuthEndpoint(\n\t\"/csrf\",\n\t{\n\t\tmethod: \"GET\",\n\t\tmetadata: HIDE_ON_CLIENT_METADATA,\n\t},\n\tasync (ctx) => {\n\t\tconst csrfToken = await ctx.getSignedCookie(\n\t\t\tctx.context.authCookies.csrfToken.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\tif (csrfToken) {\n\t\t\treturn {\n\t\t\t\tcsrfToken,\n\t\t\t};\n\t\t}\n\t\tconst token = generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\"));\n\t\tconst hash = await hs256(ctx.context.secret, token);\n\t\tconst cookie = `${token}!${hash}`;\n\t\tawait ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.csrfToken.name,\n\t\t\tcookie,\n\t\t\tctx.context.secret,\n\t\t\tctx.context.authCookies.csrfToken.options,\n\t\t);\n\t\treturn {\n\t\t\tcsrfToken: token,\n\t\t};\n\t},\n);\n","import { createAuthEndpoint } from \"../call\";\n\nexport const ok = createAuthEndpoint(\n\t\"/ok\",\n\t{\n\t\tmethod: \"GET\",\n\t},\n\tasync (ctx) => {\n\t\treturn ctx.json({\n\t\t\tok: true,\n\t\t});\n\t},\n);\n\nexport const welcome = createAuthEndpoint(\n\t\"/welcome/ok\",\n\t{\n\t\tmethod: \"GET\",\n\t},\n\tasync () => {\n\t\treturn new Response(\"Welcome to Better Auth\");\n\t},\n);\n","import { alphabet, generateRandomString } from \"oslo/crypto\";\nimport { Argon2id } from \"oslo/password\";\nimport { z } from \"zod\";\nimport { createAuthEndpoint } from \"../call\";\n\nexport const signUpEmail = createAuthEndpoint(\n\t\"/sign-up/email\",\n\t{\n\t\tmethod: \"POST\",\n\t\tbody: z.object({\n\t\t\tname: z.string(),\n\t\t\temail: z.string().email(),\n\t\t\tpassword: z.string(),\n\t\t\timage: z.string().optional(),\n\t\t\tcallbackURL: z.string().optional(),\n\t\t}),\n\t},\n\tasync (ctx) => {\n\t\tif (!ctx.context.options.emailAndPassword?.enabled) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"Email and password is not enabled\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tconst { name, email, password, image } = ctx.body;\n\t\tconst minPasswordLength =\n\t\t\tctx.context.options?.emailAndPassword?.minPasswordLength || 8;\n\t\tif (password.length < minPasswordLength) {\n\t\t\tctx.context.logger.error(\"Password is too short\");\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tbody: { message: \"Password is too short\" },\n\t\t\t});\n\t\t}\n\t\tconst argon2id = new Argon2id();\n\t\tconst dbUser = await ctx.context.internalAdapter.findUserByEmail(email);\n\t\t/**\n\t\t * hash first to avoid timing attacks\n\t\t */\n\t\tconst hash = await argon2id.hash(password);\n\t\tif (dbUser?.user) {\n\t\t\treturn ctx.json(null, {\n\t\t\t\tstatus: 400,\n\t\t\t\tbody: {\n\t\t\t\t\tmessage: \"User already exists\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tconst createdUser = await ctx.context.internalAdapter.createUser({\n\t\t\tid: generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\")),\n\t\t\temail: email.toLowerCase(),\n\t\t\tname,\n\t\t\timage,\n\t\t\temailVerified: false,\n\t\t\tcreatedAt: new Date(),\n\t\t\tupdatedAt: new Date(),\n\t\t});\n\t\t/**\n\t\t * Link the account to the user\n\t\t */\n\t\tawait ctx.context.internalAdapter.linkAccount({\n\t\t\tid: generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\")),\n\t\t\tuserId: createdUser.id,\n\t\t\tproviderId: \"credential\",\n\t\t\taccountId: createdUser.id,\n\t\t\tpassword: hash,\n\t\t});\n\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\tcreatedUser.id,\n\t\t\tctx.request,\n\t\t);\n\t\tawait ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.sessionToken.name,\n\t\t\tsession.id,\n\t\t\tctx.context.secret,\n\t\t\tctx.context.authCookies.sessionToken.options,\n\t\t);\n\t\treturn ctx.json(\n\t\t\t{\n\t\t\t\tuser: createdUser,\n\t\t\t\tsession,\n\t\t\t},\n\t\t\t{\n\t\t\t\tbody: ctx.body.callbackURL\n\t\t\t\t\t? {\n\t\t\t\t\t\t\turl: ctx.body.callbackURL,\n\t\t\t\t\t\t\tredirect: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tuser: createdUser,\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t},\n\t\t\t},\n\t\t);\n\t},\n);\n","import { createAuthEndpoint } from \"../call\";\n\nconst html = (errorCode: string = \"Unknown\") => `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Authentication Error</title>\n <style>\n :root {\n --bg-color: #f8f9fa;\n --text-color: #212529;\n --accent-color: #000000;\n --error-color: #dc3545;\n --border-color: #e9ecef;\n }\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n background-color: var(--bg-color);\n color: var(--text-color);\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100vh;\n margin: 0;\n line-height: 1.5;\n }\n .error-container {\n background-color: #ffffff;\n border-radius: 12px;\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);\n padding: 2.5rem;\n text-align: center;\n max-width: 90%;\n width: 400px;\n }\n h1 {\n color: var(--error-color);\n font-size: 1.75rem;\n margin-bottom: 1rem;\n font-weight: 600;\n }\n p {\n margin-bottom: 1.5rem;\n color: #495057;\n }\n .btn {\n background-color: var(--accent-color);\n color: #ffffff;\n text-decoration: none;\n padding: 0.75rem 1.5rem;\n border-radius: 6px;\n transition: all 0.3s ease;\n display: inline-block;\n font-weight: 500;\n border: 2px solid var(--accent-color);\n }\n .btn:hover {\n background-color: #131721;\n }\n .error-code {\n font-size: 0.875rem;\n color: #6c757d;\n margin-top: 1.5rem;\n padding-top: 1.5rem;\n border-top: 1px solid var(--border-color);\n }\n .icon {\n font-size: 3rem;\n margin-bottom: 1rem;\n }\n </style>\n</head>\n<body>\n <div class=\"error-container\">\n <div class=\"icon\">⚠️</div>\n <h1>Better Auth Error</h1>\n <p>We encountered an issue while processing your request. Please try again or contact the application owner if the problem persists.</p>\n <a href=\"#\" id=\"returnLink\" class=\"btn\">Return to Application</a>\n <div class=\"error-code\">Error Code: <span id=\"errorCode\">${errorCode}</span></div>\n </div>\n</body>\n</html>`;\n\nexport const error = createAuthEndpoint(\n\t\"/error\",\n\t{\n\t\tmethod: \"GET\",\n\t},\n\tasync (c) => {\n\t\tconst query =\n\t\t\tnew URL(c.request?.url || \"\").searchParams.get(\"error\") || \"Unknown\";\n\t\treturn new Response(html(query), {\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"text/html\",\n\t\t\t},\n\t\t});\n\t},\n);\n","import Database from \"better-sqlite3\";\nimport { Kysely } from \"kysely\";\nimport {\n\ttype Dialect,\n\tMysqlDialect,\n\tPostgresDialect,\n\tSqliteDialect,\n} from \"kysely\";\nimport { createPool } from \"mysql2\";\nimport pg from \"pg\";\nimport type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\nimport type { Adapter, Where } from \"../types/adapter\";\n\nconst { Pool } = pg;\n\nfunction convertWhere(w?: Where[]) {\n\tif (!w)\n\t\treturn {\n\t\t\tand: null,\n\t\t\tor: null,\n\t\t};\n\tconst and = w\n\t\t?.filter((w) => w.connector === \"AND\" || !w.connector)\n\t\t.reduce(\n\t\t\t(acc, w) =>\n\t\t\t\t({\n\t\t\t\t\t...acc,\n\t\t\t\t\t[w.field]: w.value,\n\t\t\t\t}) as any,\n\t\t\t{},\n\t\t);\n\tconst or = w\n\t\t?.filter((w) => w.connector === \"OR\")\n\t\t.reduce(\n\t\t\t(acc, w) =>\n\t\t\t\t({\n\t\t\t\t\t...acc,\n\t\t\t\t\t[w.field]: w.value,\n\t\t\t\t}) as any,\n\t\t\t{},\n\t\t);\n\treturn {\n\t\tand: Object.keys(and).length ? and : null,\n\t\tor: Object.keys(or).length ? or : null,\n\t};\n}\n\nfunction transformTo(\n\tval: any,\n\tfields: Record<string, FieldAttribute>,\n\ttransform: KyselyAdapterConfig[\"transform\"],\n) {\n\tfor (const key in val) {\n\t\tif (\n\t\t\tval[key] === 0 &&\n\t\t\tfields[key]?.type === \"boolean\" &&\n\t\t\ttransform?.boolean\n\t\t) {\n\t\t\tval[key] = false;\n\t\t}\n\t\tif (\n\t\t\tval[key] === 1 &&\n\t\t\tfields[key]?.type === \"boolean\" &&\n\t\t\ttransform?.boolean\n\t\t) {\n\t\t\tval[key] = true;\n\t\t}\n\t\tif (fields[key]?.type === \"date\") {\n\t\t\tif (!(val[key] instanceof Date)) {\n\t\t\t\tval[key] = new Date(val[key]);\n\t\t\t}\n\t\t}\n\t}\n\treturn val;\n}\n\nfunction transformFrom(val: any, transform: KyselyAdapterConfig[\"transform\"]) {\n\tfor (const key in val) {\n\t\tif (typeof val[key] === \"boolean\" && transform?.boolean) {\n\t\t\tval[key] = val[key] ? 1 : 0;\n\t\t}\n\t\tif (val[key] instanceof Date) {\n\t\t\tval[key] = val[key].toISOString();\n\t\t}\n\t}\n\treturn val;\n}\n\nexport interface KyselyAdapterConfig {\n\t/**\n\t * Transform dates and booleans for sqlite.\n\t */\n\ttransform?: {\n\t\tschema: {\n\t\t\t[table: string]: Record<string, FieldAttribute>;\n\t\t};\n\t\tboolean: boolean;\n\t\tdate: boolean;\n\t};\n}\n\nexport const kyselyAdapter = (\n\tdb: Kysely<any>,\n\tconfig?: KyselyAdapterConfig,\n): Adapter => {\n\treturn {\n\t\tasync create(data) {\n\t\t\tlet { model, data: val, select } = data;\n\t\t\tif (config?.transform) {\n\t\t\t\tval = transformFrom(val, config.transform);\n\t\t\t}\n\t\t\tlet res = await db\n\t\t\t\t.insertInto(model)\n\t\t\t\t.values(val as any)\n\t\t\t\t.returningAll()\n\t\t\t\t.executeTakeFirst();\n\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\tres = schema ? transformTo(val, schema, config.transform) : res;\n\t\t\t}\n\n\t\t\tif (select?.length) {\n\t\t\t\tconst data = res\n\t\t\t\t\t? select.reduce((acc, cur) => {\n\t\t\t\t\t\t\tif (res?.[cur]) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t[cur]: res[cur],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t}, {} as any)\n\t\t\t\t\t: null;\n\t\t\t\tres = data;\n\t\t\t}\n\n\t\t\treturn res as any;\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tlet query = db.selectFrom(model).selectAll();\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tlet res = await query.executeTakeFirst();\n\t\t\tif (select?.length) {\n\t\t\t\tconst data = res\n\t\t\t\t\t? select.reduce((acc, cur) => {\n\t\t\t\t\t\t\tif (res?.[cur]) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...acc,\n\t\t\t\t\t\t\t\t\t[cur]: res[cur],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t}, {} as any)\n\t\t\t\t\t: null;\n\t\t\t\tres = data;\n\t\t\t}\n\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\tres = res && schema ? transformTo(res, schema, config.transform) : res;\n\n\t\t\t\treturn res || null;\n\t\t\t}\n\t\t\treturn (res || null) as any;\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tlet query = db.selectFrom(model);\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tconst res = await query.selectAll().execute();\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\treturn schema\n\t\t\t\t\t? res.map((v) => transformTo(v, schema, config.transform))\n\t\t\t\t\t: res;\n\t\t\t}\n\t\t\treturn res as any;\n\t\t},\n\t\tasync update(data) {\n\t\t\tlet { model, where, update: val } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\n\t\t\tif (config?.transform) {\n\t\t\t\tval = transformFrom(val, config.transform);\n\t\t\t}\n\n\t\t\tlet query = db.updateTable(model).set(val);\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\t\t\tconst res = await query.returningAll().executeTakeFirst();\n\t\t\tif (config?.transform) {\n\t\t\t\tconst schema = config.transform.schema[model];\n\t\t\t\treturn schema ? transformTo(res, schema, config.transform) : res;\n\t\t\t}\n\t\t\treturn res as any;\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst { and, or } = convertWhere(where);\n\t\t\tlet query = db.deleteFrom(model);\n\n\t\t\tif (and) {\n\t\t\t\tquery = query.where((eb) => eb.and(and));\n\t\t\t}\n\t\t\tif (or) {\n\t\t\t\tquery = query.where((eb) => eb.or(or));\n\t\t\t}\n\n\t\t\tawait query.execute();\n\t\t},\n\t};\n};\n\nexport const getDialect = (config: BetterAuthOptions) => {\n\tif (!config.database) {\n\t\treturn null;\n\t}\n\tlet dialect: Dialect | null = null;\n\tif (\"provider\" in config.database) {\n\t\tconst provider = config.database.provider;\n\t\tconst connectionString = config.database.url.trim();\n\t\tif (provider === \"postgres\") {\n\t\t\tconst pool = new Pool({\n\t\t\t\tconnectionString,\n\t\t\t});\n\t\t\tdialect = new PostgresDialect({\n\t\t\t\tpool,\n\t\t\t});\n\t\t}\n\t\tif (provider === \"mysql\") {\n\t\t\tconst params = new URL(connectionString);\n\t\t\tconst pool = createPool({\n\t\t\t\thost: params.hostname,\n\t\t\t\tuser: params.username,\n\t\t\t\tpassword: params.password,\n\t\t\t\tdatabase: params.pathname.split(\"/\")[1],\n\t\t\t\tport: Number(params.port),\n\t\t\t});\n\t\t\tdialect = new MysqlDialect({ pool });\n\t\t}\n\n\t\tif (provider === \"sqlite\") {\n\t\t\tconst db = new Database(connectionString);\n\t\t\tdialect = new SqliteDialect({\n\t\t\t\tdatabase: db,\n\t\t\t});\n\t\t}\n\t}\n\treturn dialect;\n};\n\nexport const createKyselyAdapter = (config: BetterAuthOptions) => {\n\tconst dialect = getDialect(config);\n\tif (!dialect) {\n\t\treturn null;\n\t}\n\tconst db = new Kysely<any>({\n\t\tdialect,\n\t});\n\treturn db;\n};\n\nexport const getDatabaseType = (config: BetterAuthOptions) => {\n\tif (\"provider\" in config.database) {\n\t\treturn config.database.provider;\n\t}\n\tif (\"dialect\" in config.database) {\n\t\tif (config.database.dialect instanceof PostgresDialect) {\n\t\t\treturn \"postgres\";\n\t\t}\n\t\tif (config.database.dialect instanceof MysqlDialect) {\n\t\t\treturn \"mysql\";\n\t\t}\n\t\tif (config.database.dialect instanceof SqliteDialect) {\n\t\t\treturn \"sqlite\";\n\t\t}\n\t}\n\treturn \"sqlite\";\n};\n","import type { FieldAttribute } from \"../db\";\nimport type { BetterAuthOptions } from \"../types\";\n\nexport type BetterAuthDbSchema = Record<\n\tstring,\n\t{\n\t\ttableName: string;\n\t\tfields: Record<string, FieldAttribute>;\n\t\tdisableMigrations?: boolean;\n\t}\n>;\n\nexport const getAuthTables = (options: BetterAuthOptions) => {\n\tconst pluginSchema = options.plugins?.reduce((acc, plugin) => {\n\t\tconst schema = plugin.schema;\n\t\treturn {\n\t\t\t...acc,\n\t\t\t...schema,\n\t\t};\n\t}, {});\n\n\treturn {\n\t\t...pluginSchema,\n\t\tuser: {\n\t\t\ttableName: options.user?.modelName || \"user\",\n\t\t\tfields: {\n\t\t\t\tname: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\temail: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\temailVerified: {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdefaultValue: () => false,\n\t\t\t\t},\n\t\t\t\timage: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tsession: {\n\t\t\ttableName: options.session?.modelName || \"session\",\n\t\t\tfields: {\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t},\n\t\t\t\tipAddress: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tuserAgent: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\taccount: {\n\t\t\ttableName: options.account?.modelName || \"account\",\n\t\t\tfields: {\n\t\t\t\taccountId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\tproviderId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\taccessToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\trefreshToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tidToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\taccessTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\trefreshTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t} satisfies BetterAuthDbSchema;\n};\n","import { BetterAuthError } from \"../error/better-auth-error\";\nimport type { BetterAuthOptions } from \"../types\";\nimport type { Adapter } from \"../types/adapter\";\nimport { getAuthTables } from \"./get-tables\";\nimport { createKyselyAdapter, getDatabaseType, kyselyAdapter } from \"./kysely\";\n\nexport function getAdapter(options: BetterAuthOptions): Adapter {\n\tif (!options.database) {\n\t\tthrow new BetterAuthError(\"Database configuration is required\");\n\t}\n\tif (\"provider\" in options.database) {\n\t\tconst db = createKyselyAdapter(options);\n\t\tif (!db) {\n\t\t\tthrow new BetterAuthError(\"Failed to initialize database adapter\");\n\t\t}\n\t\tconst tables = getAuthTables(options);\n\t\treturn kyselyAdapter(db, {\n\t\t\ttransform: {\n\t\t\t\tschema: {\n\t\t\t\t\t[tables.user.tableName]: tables.user.fields,\n\t\t\t\t\t[tables.session.tableName]: tables.session.fields,\n\t\t\t\t\t[tables.account.tableName]: tables.account.fields,\n\t\t\t\t},\n\t\t\t\tdate: true,\n\t\t\t\tboolean: getDatabaseType(options) === \"sqlite\",\n\t\t\t},\n\t\t});\n\t}\n\treturn options.database;\n}\n","import { alphabet, generateRandomString } from \"oslo/crypto\";\nimport type { BetterAuthOptions } from \"../types\";\nimport type { Adapter } from \"../types/adapter\";\nimport { getDate } from \"../utils/date\";\nimport { getAuthTables } from \"./get-tables\";\nimport type { Account, Session, User } from \"./schema\";\n\nexport const createInternalAdapter = (\n\tadapter: Adapter,\n\toptions: BetterAuthOptions,\n) => {\n\tconst sessionExpiration = options.session?.expiresIn || 60 * 60 * 24 * 7; // 7 days\n\tconst tables = getAuthTables(options);\n\treturn {\n\t\tcreateOAuthUser: async (user: User, account: Account) => {\n\t\t\ttry {\n\t\t\t\tconst createdUser = await adapter.create({\n\t\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\t\tdata: user,\n\t\t\t\t});\n\t\t\t\tconst createdAccount = await adapter.create({\n\t\t\t\t\tmodel: tables.account.tableName,\n\t\t\t\t\tdata: account,\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tuser: createdUser,\n\t\t\t\t\taccount: createdAccount,\n\t\t\t\t};\n\t\t\t} catch (e) {\n\t\t\t\tconsole.log(e);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t},\n\t\tcreateUser: async (user: User) => {\n\t\t\tconst createdUser = await adapter.create<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\tdata: user,\n\t\t\t});\n\t\t\treturn createdUser;\n\t\t},\n\t\tcreateSession: async (userId: string, request?: Request) => {\n\t\t\tconst data: Session = {\n\t\t\t\tid: generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\")),\n\t\t\t\tuserId,\n\t\t\t\texpiresAt: getDate(sessionExpiration),\n\t\t\t\tipAddress: request?.headers.get(\"x-forwarded-for\") || \"\",\n\t\t\t\tuserAgent: request?.headers.get(\"user-agent\") || \"\",\n\t\t\t};\n\t\t\tconst session = adapter.create<Session>({\n\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\tdata,\n\t\t\t});\n\t\t\treturn session;\n\t\t},\n\t\tfindSession: async (sessionId: string) => {\n\t\t\tconst session = await adapter.findOne<Session>({\n\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: sessionId,\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!session) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst user = await adapter.findOne<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: session.userId,\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tsession,\n\t\t\t\tuser,\n\t\t\t};\n\t\t},\n\t\tupdateSession: async (session: Session) => {\n\t\t\tconst updateAge =\n\t\t\t\toptions.session?.updateAge === undefined\n\t\t\t\t\t? 1000 // 1 hour update age\n\t\t\t\t\t: options.session?.updateAge;\n\t\t\tconst updateDate = updateAge === 0 ? 0 : getDate(updateAge).valueOf();\n\t\t\tconst maxAge = getDate(sessionExpiration);\n\t\t\tconst shouldBeUpdated =\n\t\t\t\tsession.expiresAt.valueOf() - maxAge.valueOf() + updateDate <=\n\t\t\t\tDate.now();\n\t\t\tif (shouldBeUpdated) {\n\t\t\t\tconst updatedSession = await adapter.create<Session>({\n\t\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\t...session,\n\t\t\t\t\t\tid: generateRandomString(32, alphabet(\"a-z\", \"0-9\", \"A-Z\")),\n\t\t\t\t\t\texpiresAt: new Date(Date.now() + sessionExpiration),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tawait adapter.update<Session>({\n\t\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\t\twhere: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\t\tvalue: session.id,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * update the session to expire in 2 minute. This is to prevent\n\t\t\t\t\t\t * the session from expiring too quickly and logging the user out.\n\t\t\t\t\t\t */\n\t\t\t\t\t\texpiresAt: new Date(Date.now() + 1000 * 60 * 2),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn updatedSession;\n\t\t\t}\n\n\t\t\treturn session;\n\t\t},\n\t\tdeleteSession: async (id: string) => {\n\t\t\tconst session = await adapter.delete<Session>({\n\t\t\t\tmodel: tables.session.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tvalue: id,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\treturn session;\n\t\t},\n\t\tfindUserByEmail: async (email: string) => {\n\t\t\tconst user = await adapter.findOne<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: email.toLowerCase(),\n\t\t\t\t\t\tfield: \"email\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) return null;\n\t\t\tconst accounts = await adapter.findMany<Account>({\n\t\t\t\tmodel: tables.account.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tuser,\n\t\t\t\taccounts,\n\t\t\t};\n\t\t},\n\t\tfindUserById: async (userId: string) => {\n\t\t\tconst user = await adapter.findOne<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tvalue: userId,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\treturn user;\n\t\t},\n\t\tlinkAccount: async (account: Account) => {\n\t\t\tconst _account = await adapter.create<Account>({\n\t\t\t\tmodel: tables.account.tableName,\n\t\t\t\tdata: account,\n\t\t\t});\n\t\t\treturn _account;\n\t\t},\n\t\tupdateUserByEmail: async (\n\t\t\temail: string,\n\t\t\tdata: Partial<User & Record<string, any>>,\n\t\t) => {\n\t\t\tconst user = await adapter.update<User>({\n\t\t\t\tmodel: tables.user.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: email,\n\t\t\t\t\t\tfield: \"email\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tupdate: data,\n\t\t\t});\n\t\t\treturn user;\n\t\t},\n\t\tupdatePassword: async (userId: string, password: string) => {\n\t\t\tconst account = await adapter.update<Account>({\n\t\t\t\tmodel: tables.account.tableName,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: userId,\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"providerId\",\n\t\t\t\t\t\tvalue: \"credential\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tupdate: {\n\t\t\t\t\tpassword,\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn account;\n\t\t},\n\t};\n};\n\nexport type InternalAdapter = ReturnType<typeof createInternalAdapter>;\n","export const getDate = (span: number) => {\n\tconst date = new Date();\n\treturn new Date(date.getTime() + span);\n};\n","import type { ZodSchema } from \"zod\";\n\nexport const createFieldAttribute = <\n\tT extends FieldType,\n\tC extends Omit<FieldAttributeConfig<T>, \"type\">,\n>(\n\ttype: T,\n\tconfig?: C,\n) => {\n\treturn {\n\t\ttype,\n\t\t...config,\n\t} satisfies FieldAttribute<T>;\n};\n\nexport type FieldAttribute<T extends FieldType = FieldType> = {\n\ttype: T;\n} & FieldAttributeConfig<T>;\n\nexport type FieldType = \"string\" | \"number\" | \"boolean\" | \"date\";\n\nexport type InferValueType<T extends FieldType> = T extends \"string\"\n\t? string\n\t: T extends \"number\"\n\t\t? number\n\t\t: T extends \"boolean\"\n\t\t\t? boolean\n\t\t\t: T extends \"date\"\n\t\t\t\t? Date\n\t\t\t\t: never;\n\nexport type InferFieldOutput<T extends FieldAttribute> =\n\tT[\"returned\"] extends false\n\t\t? never\n\t\t: T[\"required\"] extends false\n\t\t\t? InferValueType<T[\"type\"]> | undefined\n\t\t\t: InferValueType<T[\"type\"]>;\n\nexport type FieldAttributeConfig<T extends FieldType = FieldType> = {\n\t/**\n\t * if the field should be required on a new record.\n\t * @default false\n\t */\n\trequired?: boolean;\n\t/**\n\t * If the value should be returned on a response body.\n\t * @default true\n\t */\n\treturned?: boolean;\n\t/**\n\t * If the value should be hashed when it's stored.\n\t * @default false\n\t */\n\thashValue?: boolean;\n\t/**\n\t * Default value for the field\n\t *\n\t * Note: This will not create a default value on the database level. It will only\n\t * be used when creating a new record.\n\t */\n\tdefaultValue?: InferValueType<T> | (() => InferValueType<T>);\n\t/**\n\t * transform the value before storing it.\n\t */\n\ttransform?: (value: InferValueType<T>) => InferValueType<T>;\n\t/**\n\t * Reference to another model.\n\t */\n\treferences?: {\n\t\t/**\n\t\t * The model to reference.\n\t\t */\n\t\tmodel: string;\n\t\t/**\n\t\t * The field on the referenced model.\n\t\t */\n\t\tfield: string;\n\t\t/**\n\t\t * The action to perform when the reference is deleted.\n\t\t * @default \"cascade\"\n\t\t */\n\t\tonDelete?:\n\t\t\t| \"no action\"\n\t\t\t| \"restrict\"\n\t\t\t| \"cascade\"\n\t\t\t| \"set null\"\n\t\t\t| \"set default\";\n\t};\n\tunique?: boolean;\n\t/**\n\t * A zod schema to validate the value.\n\t */\n\tvalidator?: ZodSchema;\n};\n","import type { CookieOptions } from \"better-call\";\nimport { TimeSpan } from \"oslo\";\nimport type { BetterAuthOptions } from \"../types/options\";\n\nexport function getCookies(options: BetterAuthOptions) {\n\tconst secure =\n\t\t!!options.advanced?.useSecureCookies ||\n\t\tprocess.env.NODE_ENV === \"production\";\n\tconst secureCookiePrefix = secure ? \"__Secure-\" : \"\";\n\tconst cookiePrefix = \"better-auth\";\n\tconst sessionMaxAge = new TimeSpan(7, \"d\").seconds();\n\treturn {\n\t\tsessionToken: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.session_token`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: sessionMaxAge,\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\tcsrfToken: {\n\t\t\tname: `${secureCookiePrefix ? \"__Host-\" : \"\"}${cookiePrefix}.csrf_token`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: 60 * 60 * 24 * 7,\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\tstate: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.state`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: 60 * 15, // 15 minutes in seconds\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\tpkCodeVerifier: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.pk_code_verifier`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: 60 * 15, // 15 minutes in seconds\n\t\t\t} as CookieOptions,\n\t\t},\n\t\tnonce: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.nonce`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure,\n\t\t\t\tmaxAge: 60 * 15, // 15 minutes in seconds\n\t\t\t} as CookieOptions,\n\t\t},\n\t};\n}\n\nexport function createCookieGetter(options: BetterAuthOptions) {\n\tconst secure =\n\t\t!!options.advanced?.useSecureCookies ||\n\t\tprocess.env.NODE_ENV === \"production\";\n\tconst secureCookiePrefix = secure ? \"__Secure-\" : \"\";\n\tconst cookiePrefix = \"better-auth\";\n\tfunction getCookie(cookieName: string, options?: CookieOptions) {\n\t\treturn {\n\t\t\tname:\n\t\t\t\tprocess.env.NODE_ENV === \"production\"\n\t\t\t\t\t? `${secureCookiePrefix}${cookiePrefix}.${cookieName}`\n\t\t\t\t\t: `${cookiePrefix}.${cookieName}`,\n\t\t\toptions: {\n\t\t\t\tsecure,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tmaxAge: 60 * 15, // 15 minutes in seconds\n\t\t\t\t...options,\n\t\t\t} as CookieOptions,\n\t\t};\n\t}\n\treturn getCookie;\n}\nexport type BetterAuthCookies = ReturnType<typeof getCookies>;\n","import { createConsola } from \"consola\";\n\nconst consola = createConsola({\n\tformatOptions: {\n\t\tdate: false,\n\t},\n});\n\nexport const createLogger = (options?: {\n\tdisabled?: boolean;\n}) => {\n\treturn {\n\t\tlog: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.log(\"\", ...args);\n\t\t},\n\t\terror: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.error(\"\", ...args);\n\t\t},\n\t\twarn: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.warn(\"\", ...args);\n\t\t},\n\t\tinfo: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.info(\"\", ...args);\n\t\t},\n\t\tdebug: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.debug(\"\", ...args);\n\t\t},\n\t\tbox: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.box(\"\", ...args);\n\t\t},\n\t\tsuccess: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.success(\"\", ...args);\n\t\t},\n\t\tbreak: (...args: any[]) => {\n\t\t\t!options?.disabled && console.log(\"\\n\");\n\t\t},\n\t};\n};\n\nexport const logger = createLogger();\n","import { createKyselyAdapter } from \"./adapters/kysely\";\nimport { getAdapter } from \"./adapters/utils\";\nimport { createInternalAdapter } from \"./db\";\nimport type { BetterAuthOptions } from \"./types\";\nimport { getBaseURL } from \"./utils/base-url\";\nimport {\n\ttype BetterAuthCookies,\n\tcreateCookieGetter,\n\tgetCookies,\n} from \"./utils/cookies\";\nimport { createLogger } from \"./utils/logger\";\n\nexport const init = (options: BetterAuthOptions) => {\n\tconst adapter = getAdapter(options);\n\tconst db = createKyselyAdapter(options);\n\tconst { baseURL, withPath } = getBaseURL(options.baseURL, options.basePath);\n\n\treturn {\n\t\toptions: {\n\t\t\t...options,\n\t\t\tbaseURL: baseURL,\n\t\t\tbasePath: options.basePath || \"/api/auth\",\n\t\t},\n\t\tbaseURL: withPath,\n\t\tsecret:\n\t\t\toptions.secret ||\n\t\t\tprocess.env.BETTER_AUTH_SECRET ||\n\t\t\tprocess.env.AUTH_SECRET ||\n\t\t\t\"better-auth-secret-123456789\",\n\t\tauthCookies: getCookies(options),\n\t\tlogger: createLogger({\n\t\t\tdisabled: options.disableLog,\n\t\t}),\n\t\tdb,\n\t\tadapter: adapter,\n\t\tinternalAdapter: createInternalAdapter(adapter, options),\n\t\tcreateAuthCookie: createCookieGetter(options),\n\t};\n};\n\nexport type AuthContext = {\n\toptions: BetterAuthOptions;\n\tbaseURL: string;\n\tauthCookies: BetterAuthCookies;\n\tlogger: ReturnType<typeof createLogger>;\n\tdb: ReturnType<typeof createKyselyAdapter>;\n\tadapter: ReturnType<typeof getAdapter>;\n\tinternalAdapter: ReturnType<typeof createInternalAdapter>;\n\tcreateAuthCookie: ReturnType<typeof createCookieGetter>;\n\tsecret: string;\n};\n","import type { UnionToIntersection } from \"./types/helper\";\nimport { router } from \"./api\";\nimport { init } from \"./init\";\nimport type { BetterAuthOptions } from \"./types/options\";\nimport type { BetterAuthPlugin } from \"./types/plugins\";\n\nexport const betterAuth = <O extends BetterAuthOptions>(options: O) => {\n\tconst authContext = init(options);\n\ttype PluginEndpoint = UnionToIntersection<\n\t\tO[\"plugins\"] extends Array<infer T>\n\t\t\t? T extends BetterAuthPlugin\n\t\t\t\t? {\n\t\t\t\t\t\t[key in T[\"id\"]]: T[\"endpoints\"];\n\t\t\t\t\t}\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\tconst { handler, endpoints } = router(authContext);\n\ttype Endpoint = typeof endpoints;\n\n\treturn {\n\t\thandler,\n\t\tapi: endpoints as Endpoint & PluginEndpoint,\n\t\toptions,\n\t};\n};\n\nexport type Auth = {\n\thandler: (request: Request) => Promise<Response>;\n\tapi: ReturnType<typeof router>[\"endpoints\"];\n\toptions: BetterAuthOptions;\n};\n"],"mappings":";AAAA,SAAsC,oBAAoB;;;ACA1D,SAAS,SAAS;AAIX,IAAM,gBAAgB,EAAE,OAAO;AAAA,EACrC,IAAI,EAAE,OAAO;AAAA,EACb,YAAY,EAAE,OAAO;AAAA,EACrB,WAAW,EAAE,OAAO;AAAA,EACpB,QAAQ,EAAE,OAAO;AAAA,EACjB,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC5C,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC7C,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EACxC,sBAAsB,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS;AAAA,EACnD,uBAAuB,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA,EAIpD,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAC1C,CAAC;AAEM,IAAM,aAAa,EAAE,OAAO;AAAA,EAClC,IAAI,EAAE,OAAO;AAAA,EACb,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,QAAQ,IAAI,YAAY,CAAC;AAAA,EACtD,eAAe,EAAE,QAAQ,EAAE,QAAQ,KAAK;AAAA,EACxC,MAAM,E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AAU,QAAQ,YAAY;AAAA,IAC/B;AAAA,IACA,SAASA;AAAA,IACT,QACC,QAAQ,UACR,QAAQ,IAAI,sBACZ,QAAQ,IAAI,eACZ;AAAA,IACD,aAAa,WAAW,OAAO;AAAA,IAC/B,QAAQ,aAAa;AAAA,MACpB,UAAU,QAAQ;AAAA,IACnB,CAAC;AAAA,IACD;AAAA,IACA;AAAA,IACA,iBAAiB,sBAAsB,SAAS,OAAO;AAAA,IACvD,kBAAkB,mBAAmB,OAAO;AAAA,EAC7C;AACD;;;AChCO,IAAM,aAAa,CAA8B,YAAe;AACtE,QAAM,cAAc,KAAK,OAAO;AAUhC,QAAM,EAAE,SAAS,UAAU,IAAI,OAAO,WAAW;AAGjD,SAAO;AAAA,IACN;AAAA,IACA,KAAK;AAAA,IACL;AAAA,EACD;AACD;","names":["z","z","APIError","z","error","betterFetch","error","betterFetch","betterFetch","error","betterFetch","betterFetch","error","betterFetch","parseJWT","parseJWT","betterFetch","error","betterFetch","betterFetch","error","betterFetch","betterFetch","error","betterFetch","z","APIError","APIError","z","z","APIError","z","z","Argon2id","z","z","Argon2id","TimeSpan","createJWT","validateJWT","z","z","createJWT","TimeSpan","validateJWT","alphabet","generateRandomString","generateRandomString","alphabet","alphabet","generateRandomString","Argon2id","z","z","Argon2id","generateRandomString","alphabet","ctx","w","data","alphabet","generateRandomString","generateRandomString","alphabet","TimeSpan","options","withPath"]}
|