better-auth 1.4.7-beta.2 → 1.4.7-beta.4
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/api/index.d.mts +103 -221
- package/dist/api/index.mjs +1 -1
- package/dist/api/index.mjs.map +1 -1
- package/dist/api/routes/account.d.mts +11 -23
- package/dist/api/routes/callback.d.mts +3 -5
- package/dist/api/routes/email-verification.d.mts +4 -8
- package/dist/api/routes/error.d.mts +3 -5
- package/dist/api/routes/ok.d.mts +3 -5
- package/dist/api/routes/reset-password.d.mts +5 -11
- package/dist/api/routes/session.d.mts +17 -25
- package/dist/api/routes/session.mjs +8 -0
- package/dist/api/routes/session.mjs.map +1 -1
- package/dist/api/routes/sign-in.d.mts +3 -7
- package/dist/api/routes/sign-out.d.mts +2 -4
- package/dist/api/routes/sign-up.d.mts +2 -4
- package/dist/api/routes/update-user.d.mts +13 -28
- package/dist/api/routes/update-user.mjs +1 -2
- package/dist/api/routes/update-user.mjs.map +1 -1
- package/dist/api/to-auth-endpoints.mjs.map +1 -1
- package/dist/client/lynx/index.d.mts +1 -1
- package/dist/client/path-to-object.d.mts +4 -0
- package/dist/client/react/index.d.mts +1 -1
- package/dist/client/solid/index.d.mts +1 -1
- package/dist/client/svelte/index.d.mts +1 -1
- package/dist/client/vanilla.d.mts +15 -15
- package/dist/client/vue/index.d.mts +1 -1
- package/dist/cookies/index.mjs +2 -2
- package/dist/cookies/index.mjs.map +1 -1
- package/dist/db/field.d.mts +5 -5
- package/dist/integrations/next-js.d.mts +4 -4
- package/dist/integrations/svelte-kit.d.mts +2 -2
- package/dist/integrations/tanstack-start.d.mts +4 -4
- package/dist/plugins/admin/admin.d.mts +118 -147
- package/dist/plugins/admin/admin.mjs.map +1 -1
- package/dist/plugins/admin/error-codes.mjs +2 -1
- package/dist/plugins/admin/error-codes.mjs.map +1 -1
- package/dist/plugins/admin/routes.mjs +15 -1
- package/dist/plugins/admin/routes.mjs.map +1 -1
- package/dist/plugins/anonymous/index.d.mts +5 -7
- package/dist/plugins/api-key/index.d.mts +59 -79
- package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs +1 -4
- package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs.map +1 -1
- package/dist/plugins/api-key/routes/verify-api-key.mjs +26 -5
- package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -1
- package/dist/plugins/bearer/index.d.mts +6 -6
- package/dist/plugins/captcha/index.d.mts +2 -2
- package/dist/plugins/custom-session/index.d.mts +3 -5
- package/dist/plugins/device-authorization/index.d.mts +9 -19
- package/dist/plugins/device-authorization/index.mjs +6 -5
- package/dist/plugins/device-authorization/index.mjs.map +1 -1
- package/dist/plugins/device-authorization/routes.mjs +1 -1
- package/dist/plugins/device-authorization/routes.mjs.map +1 -1
- package/dist/plugins/email-otp/index.d.mts +13 -31
- package/dist/plugins/email-otp/routes.mjs +26 -32
- package/dist/plugins/email-otp/routes.mjs.map +1 -1
- package/dist/plugins/generic-oauth/index.d.mts +6 -12
- package/dist/plugins/haveibeenpwned/index.d.mts +3 -3
- package/dist/plugins/jwt/client.d.mts +2 -2
- package/dist/plugins/jwt/index.d.mts +11 -21
- package/dist/plugins/jwt/index.mjs +7 -13
- package/dist/plugins/jwt/index.mjs.map +1 -1
- package/dist/plugins/jwt/utils.mjs +2 -2
- package/dist/plugins/jwt/utils.mjs.map +1 -1
- package/dist/plugins/last-login-method/index.d.mts +4 -4
- package/dist/plugins/magic-link/index.d.mts +4 -8
- package/dist/plugins/mcp/index.d.mts +13 -27
- package/dist/plugins/mcp/index.mjs +3 -3
- package/dist/plugins/mcp/index.mjs.map +1 -1
- package/dist/plugins/multi-session/index.d.mts +14 -20
- package/dist/plugins/oauth-proxy/index.d.mts +10 -12
- package/dist/plugins/oauth-proxy/index.mjs.map +1 -1
- package/dist/plugins/oidc-provider/index.d.mts +19 -35
- package/dist/plugins/oidc-provider/index.mjs +6 -4
- package/dist/plugins/oidc-provider/index.mjs.map +1 -1
- package/dist/plugins/one-tap/client.d.mts +4 -4
- package/dist/plugins/one-tap/index.d.mts +2 -4
- package/dist/plugins/one-time-token/index.d.mts +4 -8
- package/dist/plugins/open-api/generator.mjs +2 -2
- package/dist/plugins/open-api/generator.mjs.map +1 -1
- package/dist/plugins/open-api/index.d.mts +4 -8
- package/dist/plugins/open-api/index.mjs +3 -1
- package/dist/plugins/open-api/index.mjs.map +1 -1
- package/dist/plugins/organization/client.d.mts +17 -17
- package/dist/plugins/organization/organization.d.mts +3 -5
- package/dist/plugins/organization/routes/crud-access-control.d.mts +22 -32
- package/dist/plugins/organization/routes/crud-invites.d.mts +58 -72
- package/dist/plugins/organization/routes/crud-members.d.mts +62 -77
- package/dist/plugins/organization/routes/crud-members.mjs +1 -2
- package/dist/plugins/organization/routes/crud-members.mjs.map +1 -1
- package/dist/plugins/organization/routes/crud-org.d.mts +0 -14
- package/dist/plugins/organization/routes/crud-team.d.mts +76 -94
- package/dist/plugins/phone-number/index.d.mts +9 -19
- package/dist/plugins/siwe/index.d.mts +3 -7
- package/dist/plugins/two-factor/backup-codes/index.d.mts +1 -10
- package/dist/plugins/two-factor/backup-codes/index.mjs +2 -3
- package/dist/plugins/two-factor/backup-codes/index.mjs.map +1 -1
- package/dist/plugins/two-factor/index.d.mts +20 -44
- package/dist/plugins/two-factor/index.mjs.map +1 -1
- package/dist/plugins/two-factor/otp/index.d.mts +0 -4
- package/dist/plugins/two-factor/totp/index.d.mts +1 -8
- package/dist/plugins/two-factor/totp/index.mjs +12 -15
- package/dist/plugins/two-factor/totp/index.mjs.map +1 -1
- package/dist/plugins/username/index.d.mts +9 -13
- package/dist/plugins/username/schema.d.mts +3 -3
- package/dist/test-utils/test-instance.d.mts +1173 -1593
- package/dist/utils/hide-metadata.d.mts +1 -1
- package/dist/utils/hide-metadata.mjs +1 -1
- package/dist/utils/hide-metadata.mjs.map +1 -1
- package/dist/utils/time.d.mts +21 -0
- package/dist/utils/time.mjs +85 -44
- package/dist/utils/time.mjs.map +1 -1
- package/package.json +5 -6
package/dist/api/index.mjs
CHANGED
|
@@ -25,7 +25,7 @@ function checkEndpointConflicts(options, logger$1) {
|
|
|
25
25
|
const endpointRegistry = /* @__PURE__ */ new Map();
|
|
26
26
|
options.plugins?.forEach((plugin) => {
|
|
27
27
|
if (plugin.endpoints) {
|
|
28
|
-
for (const [key, endpoint] of Object.entries(plugin.endpoints)) if (endpoint && "path" in endpoint) {
|
|
28
|
+
for (const [key, endpoint] of Object.entries(plugin.endpoints)) if (endpoint && "path" in endpoint && typeof endpoint.path === "string") {
|
|
29
29
|
const path = endpoint.path;
|
|
30
30
|
let methods = [];
|
|
31
31
|
if (endpoint.options && "method" in endpoint.options) {
|
package/dist/api/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["methods: string[]","conflicts: {\n\t\tpath: string;\n\t\tplugins: string[];\n\t\tconflictingMethods: string[];\n\t}[]","conflictingMethods: string[]","APIError"],"sources":["../../src/api/index.ts"],"sourcesContent":["import type {\n\tAuthContext,\n\tBetterAuthOptions,\n\tBetterAuthPlugin,\n} from \"@better-auth/core\";\nimport type { InternalLogger } from \"@better-auth/core/env\";\nimport { logger } from \"@better-auth/core/env\";\nimport type { Endpoint, Middleware } from \"better-call\";\nimport { APIError, createRouter } from \"better-call\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport { originCheckMiddleware } from \"./middlewares\";\nimport { onRequestRateLimit } from \"./rate-limiter\";\nimport {\n\taccountInfo,\n\tcallbackOAuth,\n\tchangeEmail,\n\tchangePassword,\n\tdeleteUser,\n\tdeleteUserCallback,\n\terror,\n\tgetAccessToken,\n\tgetSession,\n\tlinkSocialAccount,\n\tlistSessions,\n\tlistUserAccounts,\n\tok,\n\trefreshToken,\n\trequestPasswordReset,\n\trequestPasswordResetCallback,\n\tresetPassword,\n\trevokeOtherSessions,\n\trevokeSession,\n\trevokeSessions,\n\tsendVerificationEmail,\n\tsetPassword,\n\tsignInEmail,\n\tsignInSocial,\n\tsignOut,\n\tsignUpEmail,\n\tunlinkAccount,\n\tupdateUser,\n\tverifyEmail,\n} from \"./routes\";\nimport { toAuthEndpoints } from \"./to-auth-endpoints\";\n\nexport function checkEndpointConflicts(\n\toptions: BetterAuthOptions,\n\tlogger: InternalLogger,\n) {\n\tconst endpointRegistry = new Map<\n\t\tstring,\n\t\t{ pluginId: string; endpointKey: string; methods: string[] }[]\n\t>();\n\n\toptions.plugins?.forEach((plugin) => {\n\t\tif (plugin.endpoints) {\n\t\t\tfor (const [key, endpoint] of Object.entries(plugin.endpoints)) {\n\t\t\t\tif (endpoint && \"path\" in endpoint) {\n\t\t\t\t\tconst path = endpoint.path;\n\t\t\t\t\tlet methods: string[] = [];\n\t\t\t\t\tif (endpoint.options && \"method\" in endpoint.options) {\n\t\t\t\t\t\tif (Array.isArray(endpoint.options.method)) {\n\t\t\t\t\t\t\tmethods = endpoint.options.method;\n\t\t\t\t\t\t} else if (typeof endpoint.options.method === \"string\") {\n\t\t\t\t\t\t\tmethods = [endpoint.options.method];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (methods.length === 0) {\n\t\t\t\t\t\tmethods = [\"*\"];\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!endpointRegistry.has(path)) {\n\t\t\t\t\t\tendpointRegistry.set(path, []);\n\t\t\t\t\t}\n\t\t\t\t\tendpointRegistry.get(path)!.push({\n\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\tendpointKey: key,\n\t\t\t\t\t\tmethods,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n\n\tconst conflicts: {\n\t\tpath: string;\n\t\tplugins: string[];\n\t\tconflictingMethods: string[];\n\t}[] = [];\n\tfor (const [path, entries] of endpointRegistry.entries()) {\n\t\tif (entries.length > 1) {\n\t\t\tconst methodMap = new Map<string, string[]>();\n\t\t\tlet hasConflict = false;\n\n\t\t\tfor (const entry of entries) {\n\t\t\t\tfor (const method of entry.methods) {\n\t\t\t\t\tif (!methodMap.has(method)) {\n\t\t\t\t\t\tmethodMap.set(method, []);\n\t\t\t\t\t}\n\t\t\t\t\tmethodMap.get(method)!.push(entry.pluginId);\n\n\t\t\t\t\tif (methodMap.get(method)!.length > 1) {\n\t\t\t\t\t\thasConflict = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (method === \"*\" && entries.length > 1) {\n\t\t\t\t\t\thasConflict = true;\n\t\t\t\t\t} else if (method !== \"*\" && methodMap.has(\"*\")) {\n\t\t\t\t\t\thasConflict = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (hasConflict) {\n\t\t\t\tconst uniquePlugins = [...new Set(entries.map((e) => e.pluginId))];\n\t\t\t\tconst conflictingMethods: string[] = [];\n\n\t\t\t\tfor (const [method, plugins] of methodMap.entries()) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tplugins.length > 1 ||\n\t\t\t\t\t\t(method === \"*\" && entries.length > 1) ||\n\t\t\t\t\t\t(method !== \"*\" && methodMap.has(\"*\"))\n\t\t\t\t\t) {\n\t\t\t\t\t\tconflictingMethods.push(method);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconflicts.push({\n\t\t\t\t\tpath,\n\t\t\t\t\tplugins: uniquePlugins,\n\t\t\t\t\tconflictingMethods,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tif (conflicts.length > 0) {\n\t\tconst conflictMessages = conflicts\n\t\t\t.map(\n\t\t\t\t(conflict) =>\n\t\t\t\t\t` - \"${conflict.path}\" [${conflict.conflictingMethods.join(\", \")}] used by plugins: ${conflict.plugins.join(\", \")}`,\n\t\t\t)\n\t\t\t.join(\"\\n\");\n\t\tlogger.error(\n\t\t\t`Endpoint path conflicts detected! Multiple plugins are trying to use the same endpoint paths with conflicting HTTP methods:\n${conflictMessages}\n\nTo resolve this, you can:\n\t1. Use only one of the conflicting plugins\n\t2. Configure the plugins to use different paths (if supported)\n\t3. Ensure plugins use different HTTP methods for the same path\n`,\n\t\t);\n\t}\n}\n\nexport function getEndpoints<Option extends BetterAuthOptions>(\n\tctx: Promise<AuthContext> | AuthContext,\n\toptions: Option,\n) {\n\tconst pluginEndpoints =\n\t\toptions.plugins?.reduce<Record<string, Endpoint>>((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\n\ttype PluginEndpoint = UnionToIntersection<\n\t\tOption[\"plugins\"] extends Array<infer T>\n\t\t\t? T extends BetterAuthPlugin\n\t\t\t\t? T extends {\n\t\t\t\t\t\tendpoints: infer E;\n\t\t\t\t\t}\n\t\t\t\t\t? E\n\t\t\t\t\t: {}\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst middlewares =\n\t\toptions.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\tconst authContext = await ctx;\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...authContext,\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 Middleware;\n\t\t\t\t\tmiddleware.options = m.middleware.options;\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\tconst baseEndpoints = {\n\t\tsignInSocial: signInSocial<Option>(),\n\t\tcallbackOAuth,\n\t\tgetSession: getSession<Option>(),\n\t\tsignOut,\n\t\tsignUpEmail: signUpEmail<Option>(),\n\t\tsignInEmail: signInEmail<Option>(),\n\t\tresetPassword,\n\t\tverifyEmail,\n\t\tsendVerificationEmail,\n\t\tchangeEmail,\n\t\tchangePassword,\n\t\tsetPassword,\n\t\tupdateUser: updateUser<Option>(),\n\t\tdeleteUser,\n\t\trequestPasswordReset,\n\t\trequestPasswordResetCallback,\n\t\tlistSessions: listSessions<Option>(),\n\t\trevokeSession,\n\t\trevokeSessions,\n\t\trevokeOtherSessions,\n\t\tlinkSocialAccount,\n\t\tlistUserAccounts,\n\t\tdeleteUserCallback,\n\t\tunlinkAccount,\n\t\trefreshToken,\n\t\tgetAccessToken,\n\t\taccountInfo,\n\t};\n\tconst endpoints = {\n\t\t...baseEndpoints,\n\t\t...pluginEndpoints,\n\t\tok,\n\t\terror,\n\t} as const;\n\tconst api = toAuthEndpoints(endpoints, ctx);\n\treturn {\n\t\tapi: api as typeof endpoints & PluginEndpoint,\n\t\tmiddlewares,\n\t};\n}\nexport const router = <Option extends BetterAuthOptions>(\n\tctx: AuthContext,\n\toptions: Option,\n) => {\n\tconst { api, middlewares } = getEndpoints(ctx, options);\n\tconst basePath = new URL(ctx.baseURL).pathname;\n\n\treturn createRouter(api, {\n\t\trouterContext: ctx,\n\t\topenapi: {\n\t\t\tdisabled: true,\n\t\t},\n\t\tbasePath,\n\t\trouterMiddleware: [\n\t\t\t{\n\t\t\t\tpath: \"/**\",\n\t\t\t\tmiddleware: originCheckMiddleware,\n\t\t\t},\n\t\t\t...middlewares,\n\t\t],\n\t\tallowedMediaTypes: [\"application/json\"],\n\t\tasync onRequest(req) {\n\t\t\t//handle disabled paths\n\t\t\tconst disabledPaths = ctx.options.disabledPaths || [];\n\t\t\tconst pathname = new URL(req.url).pathname.replace(/\\/+$/, \"\") || \"/\";\n\t\t\tconst normalizedPath =\n\t\t\t\tbasePath === \"/\"\n\t\t\t\t\t? pathname\n\t\t\t\t\t: pathname.startsWith(basePath)\n\t\t\t\t\t\t? pathname.slice(basePath.length).replace(/\\/+$/, \"\") || \"/\"\n\t\t\t\t\t\t: pathname;\n\t\t\tif (disabledPaths.includes(normalizedPath)) {\n\t\t\t\treturn new Response(\"Not Found\", { status: 404 });\n\t\t\t}\n\t\t\tfor (const plugin of ctx.options.plugins || []) {\n\t\t\t\tif (plugin.onRequest) {\n\t\t\t\t\tconst response = await plugin.onRequest(req, ctx);\n\t\t\t\t\tif (response && \"response\" in response) {\n\t\t\t\t\t\treturn response.response;\n\t\t\t\t\t}\n\t\t\t\t\tif (response && \"request\" in response) {\n\t\t\t\t\t\tconst rateLimitResponse = await onRequestRateLimit(\n\t\t\t\t\t\t\tresponse.request,\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (rateLimitResponse) {\n\t\t\t\t\t\t\treturn rateLimitResponse;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn response.request;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn onRequestRateLimit(req, ctx);\n\t\t},\n\t\tasync onResponse(res) {\n\t\t\tfor (const plugin of ctx.options.plugins || []) {\n\t\t\t\tif (plugin.onResponse) {\n\t\t\t\t\tconst response = await plugin.onResponse(res, ctx);\n\t\t\t\t\tif (response) {\n\t\t\t\t\t\treturn response.response;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t},\n\t\tonError(e) {\n\t\t\tif (e instanceof APIError && e.status === \"FOUND\") {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (options.onAPIError?.throw) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t\tif (options.onAPIError?.onError) {\n\t\t\t\toptions.onAPIError.onError(e, ctx);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst optLogLevel = options.logger?.level;\n\t\t\tconst log =\n\t\t\t\toptLogLevel === \"error\" ||\n\t\t\t\toptLogLevel === \"warn\" ||\n\t\t\t\toptLogLevel === \"debug\"\n\t\t\t\t\t? logger\n\t\t\t\t\t: undefined;\n\t\t\tif (options.logger?.disabled !== true) {\n\t\t\t\tif (\n\t\t\t\t\te &&\n\t\t\t\t\ttypeof e === \"object\" &&\n\t\t\t\t\t\"message\" in e &&\n\t\t\t\t\ttypeof e.message === \"string\"\n\t\t\t\t) {\n\t\t\t\t\tif (\n\t\t\t\t\t\te.message.includes(\"no column\") ||\n\t\t\t\t\t\te.message.includes(\"column\") ||\n\t\t\t\t\t\te.message.includes(\"relation\") ||\n\t\t\t\t\t\te.message.includes(\"table\") ||\n\t\t\t\t\t\te.message.includes(\"does not exist\")\n\t\t\t\t\t) {\n\t\t\t\t\t\tctx.logger?.error(e.message);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (e instanceof APIError) {\n\t\t\t\t\tif (e.status === \"INTERNAL_SERVER_ERROR\") {\n\t\t\t\t\t\tctx.logger.error(e.status, e);\n\t\t\t\t\t}\n\t\t\t\t\tlog?.error(e.message);\n\t\t\t\t} else {\n\t\t\t\t\tctx.logger?.error(\n\t\t\t\t\t\te && typeof e === \"object\" && \"name\" in e ? (e.name as string) : \"\",\n\t\t\t\t\t\te,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t});\n};\n\nexport {\n\ttype AuthEndpoint,\n\ttype AuthMiddleware,\n\tcreateAuthEndpoint,\n\tcreateAuthMiddleware,\n\toptionsMiddleware,\n} from \"@better-auth/core/api\";\nexport { APIError } from \"better-call\";\nexport { getIp } from \"../utils/get-request-ip\";\nexport * from \"./middlewares\";\nexport * from \"./routes\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,uBACf,SACA,UACC;CACD,MAAM,mCAAmB,IAAI,KAG1B;AAEH,SAAQ,SAAS,SAAS,WAAW;AACpC,MAAI,OAAO,WACV;QAAK,MAAM,CAAC,KAAK,aAAa,OAAO,QAAQ,OAAO,UAAU,CAC7D,KAAI,YAAY,UAAU,UAAU;IACnC,MAAM,OAAO,SAAS;IACtB,IAAIA,UAAoB,EAAE;AAC1B,QAAI,SAAS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AACJ,OAAI,QAAQ,QAAQ,aAAa,MAAM;AACtC,QACC,KACA,OAAO,MAAM,YACb,aAAa,KACb,OAAO,EAAE,YAAY,UAErB;SACC,EAAE,QAAQ,SAAS,YAAY,IAC/B,EAAE,QAAQ,SAAS,SAAS,IAC5B,EAAE,QAAQ,SAAS,WAAW,IAC9B,EAAE,QAAQ,SAAS,QAAQ,IAC3B,EAAE,QAAQ,SAAS,iBAAiB,EACnC;AACD,UAAI,QAAQ,MAAM,EAAE,QAAQ;AAC5B;;;AAIF,QAAI,aAAaA,YAAU;AAC1B,SAAI,EAAE,WAAW,wBAChB,KAAI,OAAO,MAAM,EAAE,QAAQ,EAAE;AAE9B,UAAK,MAAM,EAAE,QAAQ;UAErB,KAAI,QAAQ,MACX,KAAK,OAAO,MAAM,YAAY,UAAU,IAAK,EAAE,OAAkB,IACjE,EACA;;;EAIJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["methods: string[]","conflicts: {\n\t\tpath: string;\n\t\tplugins: string[];\n\t\tconflictingMethods: string[];\n\t}[]","conflictingMethods: string[]","APIError"],"sources":["../../src/api/index.ts"],"sourcesContent":["import type {\n\tAuthContext,\n\tBetterAuthOptions,\n\tBetterAuthPlugin,\n} from \"@better-auth/core\";\nimport type { InternalLogger } from \"@better-auth/core/env\";\nimport { logger } from \"@better-auth/core/env\";\nimport type { Endpoint, Middleware } from \"better-call\";\nimport { APIError, createRouter } from \"better-call\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport { originCheckMiddleware } from \"./middlewares\";\nimport { onRequestRateLimit } from \"./rate-limiter\";\nimport {\n\taccountInfo,\n\tcallbackOAuth,\n\tchangeEmail,\n\tchangePassword,\n\tdeleteUser,\n\tdeleteUserCallback,\n\terror,\n\tgetAccessToken,\n\tgetSession,\n\tlinkSocialAccount,\n\tlistSessions,\n\tlistUserAccounts,\n\tok,\n\trefreshToken,\n\trequestPasswordReset,\n\trequestPasswordResetCallback,\n\tresetPassword,\n\trevokeOtherSessions,\n\trevokeSession,\n\trevokeSessions,\n\tsendVerificationEmail,\n\tsetPassword,\n\tsignInEmail,\n\tsignInSocial,\n\tsignOut,\n\tsignUpEmail,\n\tunlinkAccount,\n\tupdateUser,\n\tverifyEmail,\n} from \"./routes\";\nimport { toAuthEndpoints } from \"./to-auth-endpoints\";\n\nexport function checkEndpointConflicts(\n\toptions: BetterAuthOptions,\n\tlogger: InternalLogger,\n) {\n\tconst endpointRegistry = new Map<\n\t\tstring,\n\t\t{ pluginId: string; endpointKey: string; methods: string[] }[]\n\t>();\n\n\toptions.plugins?.forEach((plugin) => {\n\t\tif (plugin.endpoints) {\n\t\t\tfor (const [key, endpoint] of Object.entries(plugin.endpoints)) {\n\t\t\t\tif (\n\t\t\t\t\tendpoint &&\n\t\t\t\t\t\"path\" in endpoint &&\n\t\t\t\t\ttypeof endpoint.path === \"string\"\n\t\t\t\t) {\n\t\t\t\t\tconst path = endpoint.path;\n\t\t\t\t\tlet methods: string[] = [];\n\t\t\t\t\tif (endpoint.options && \"method\" in endpoint.options) {\n\t\t\t\t\t\tif (Array.isArray(endpoint.options.method)) {\n\t\t\t\t\t\t\tmethods = endpoint.options.method;\n\t\t\t\t\t\t} else if (typeof endpoint.options.method === \"string\") {\n\t\t\t\t\t\t\tmethods = [endpoint.options.method];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (methods.length === 0) {\n\t\t\t\t\t\tmethods = [\"*\"];\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!endpointRegistry.has(path)) {\n\t\t\t\t\t\tendpointRegistry.set(path, []);\n\t\t\t\t\t}\n\t\t\t\t\tendpointRegistry.get(path)!.push({\n\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\tendpointKey: key,\n\t\t\t\t\t\tmethods,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n\n\tconst conflicts: {\n\t\tpath: string;\n\t\tplugins: string[];\n\t\tconflictingMethods: string[];\n\t}[] = [];\n\tfor (const [path, entries] of endpointRegistry.entries()) {\n\t\tif (entries.length > 1) {\n\t\t\tconst methodMap = new Map<string, string[]>();\n\t\t\tlet hasConflict = false;\n\n\t\t\tfor (const entry of entries) {\n\t\t\t\tfor (const method of entry.methods) {\n\t\t\t\t\tif (!methodMap.has(method)) {\n\t\t\t\t\t\tmethodMap.set(method, []);\n\t\t\t\t\t}\n\t\t\t\t\tmethodMap.get(method)!.push(entry.pluginId);\n\n\t\t\t\t\tif (methodMap.get(method)!.length > 1) {\n\t\t\t\t\t\thasConflict = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (method === \"*\" && entries.length > 1) {\n\t\t\t\t\t\thasConflict = true;\n\t\t\t\t\t} else if (method !== \"*\" && methodMap.has(\"*\")) {\n\t\t\t\t\t\thasConflict = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (hasConflict) {\n\t\t\t\tconst uniquePlugins = [...new Set(entries.map((e) => e.pluginId))];\n\t\t\t\tconst conflictingMethods: string[] = [];\n\n\t\t\t\tfor (const [method, plugins] of methodMap.entries()) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tplugins.length > 1 ||\n\t\t\t\t\t\t(method === \"*\" && entries.length > 1) ||\n\t\t\t\t\t\t(method !== \"*\" && methodMap.has(\"*\"))\n\t\t\t\t\t) {\n\t\t\t\t\t\tconflictingMethods.push(method);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconflicts.push({\n\t\t\t\t\tpath,\n\t\t\t\t\tplugins: uniquePlugins,\n\t\t\t\t\tconflictingMethods,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tif (conflicts.length > 0) {\n\t\tconst conflictMessages = conflicts\n\t\t\t.map(\n\t\t\t\t(conflict) =>\n\t\t\t\t\t` - \"${conflict.path}\" [${conflict.conflictingMethods.join(\", \")}] used by plugins: ${conflict.plugins.join(\", \")}`,\n\t\t\t)\n\t\t\t.join(\"\\n\");\n\t\tlogger.error(\n\t\t\t`Endpoint path conflicts detected! Multiple plugins are trying to use the same endpoint paths with conflicting HTTP methods:\n${conflictMessages}\n\nTo resolve this, you can:\n\t1. Use only one of the conflicting plugins\n\t2. Configure the plugins to use different paths (if supported)\n\t3. Ensure plugins use different HTTP methods for the same path\n`,\n\t\t);\n\t}\n}\n\nexport function getEndpoints<Option extends BetterAuthOptions>(\n\tctx: Promise<AuthContext> | AuthContext,\n\toptions: Option,\n) {\n\tconst pluginEndpoints =\n\t\toptions.plugins?.reduce<Record<string, Endpoint>>((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\n\ttype PluginEndpoint = UnionToIntersection<\n\t\tOption[\"plugins\"] extends Array<infer T>\n\t\t\t? T extends BetterAuthPlugin\n\t\t\t\t? T extends {\n\t\t\t\t\t\tendpoints: infer E;\n\t\t\t\t\t}\n\t\t\t\t\t? E\n\t\t\t\t\t: {}\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst middlewares =\n\t\toptions.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\tconst authContext = await ctx;\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...authContext,\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 Middleware;\n\t\t\t\t\tmiddleware.options = m.middleware.options;\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\tconst baseEndpoints = {\n\t\tsignInSocial: signInSocial<Option>(),\n\t\tcallbackOAuth,\n\t\tgetSession: getSession<Option>(),\n\t\tsignOut,\n\t\tsignUpEmail: signUpEmail<Option>(),\n\t\tsignInEmail: signInEmail<Option>(),\n\t\tresetPassword,\n\t\tverifyEmail,\n\t\tsendVerificationEmail,\n\t\tchangeEmail,\n\t\tchangePassword,\n\t\tsetPassword,\n\t\tupdateUser: updateUser<Option>(),\n\t\tdeleteUser,\n\t\trequestPasswordReset,\n\t\trequestPasswordResetCallback,\n\t\tlistSessions: listSessions<Option>(),\n\t\trevokeSession,\n\t\trevokeSessions,\n\t\trevokeOtherSessions,\n\t\tlinkSocialAccount,\n\t\tlistUserAccounts,\n\t\tdeleteUserCallback,\n\t\tunlinkAccount,\n\t\trefreshToken,\n\t\tgetAccessToken,\n\t\taccountInfo,\n\t};\n\tconst endpoints = {\n\t\t...baseEndpoints,\n\t\t...pluginEndpoints,\n\t\tok,\n\t\terror,\n\t} as const;\n\tconst api = toAuthEndpoints(endpoints, ctx);\n\treturn {\n\t\tapi: api as typeof endpoints & PluginEndpoint,\n\t\tmiddlewares,\n\t};\n}\nexport const router = <Option extends BetterAuthOptions>(\n\tctx: AuthContext,\n\toptions: Option,\n) => {\n\tconst { api, middlewares } = getEndpoints(ctx, options);\n\tconst basePath = new URL(ctx.baseURL).pathname;\n\n\treturn createRouter(api, {\n\t\trouterContext: ctx,\n\t\topenapi: {\n\t\t\tdisabled: true,\n\t\t},\n\t\tbasePath,\n\t\trouterMiddleware: [\n\t\t\t{\n\t\t\t\tpath: \"/**\",\n\t\t\t\tmiddleware: originCheckMiddleware,\n\t\t\t},\n\t\t\t...middlewares,\n\t\t],\n\t\tallowedMediaTypes: [\"application/json\"],\n\t\tasync onRequest(req) {\n\t\t\t//handle disabled paths\n\t\t\tconst disabledPaths = ctx.options.disabledPaths || [];\n\t\t\tconst pathname = new URL(req.url).pathname.replace(/\\/+$/, \"\") || \"/\";\n\t\t\tconst normalizedPath =\n\t\t\t\tbasePath === \"/\"\n\t\t\t\t\t? pathname\n\t\t\t\t\t: pathname.startsWith(basePath)\n\t\t\t\t\t\t? pathname.slice(basePath.length).replace(/\\/+$/, \"\") || \"/\"\n\t\t\t\t\t\t: pathname;\n\t\t\tif (disabledPaths.includes(normalizedPath)) {\n\t\t\t\treturn new Response(\"Not Found\", { status: 404 });\n\t\t\t}\n\t\t\tfor (const plugin of ctx.options.plugins || []) {\n\t\t\t\tif (plugin.onRequest) {\n\t\t\t\t\tconst response = await plugin.onRequest(req, ctx);\n\t\t\t\t\tif (response && \"response\" in response) {\n\t\t\t\t\t\treturn response.response;\n\t\t\t\t\t}\n\t\t\t\t\tif (response && \"request\" in response) {\n\t\t\t\t\t\tconst rateLimitResponse = await onRequestRateLimit(\n\t\t\t\t\t\t\tresponse.request,\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (rateLimitResponse) {\n\t\t\t\t\t\t\treturn rateLimitResponse;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn response.request;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn onRequestRateLimit(req, ctx);\n\t\t},\n\t\tasync onResponse(res) {\n\t\t\tfor (const plugin of ctx.options.plugins || []) {\n\t\t\t\tif (plugin.onResponse) {\n\t\t\t\t\tconst response = await plugin.onResponse(res, ctx);\n\t\t\t\t\tif (response) {\n\t\t\t\t\t\treturn response.response;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t},\n\t\tonError(e) {\n\t\t\tif (e instanceof APIError && e.status === \"FOUND\") {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (options.onAPIError?.throw) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t\tif (options.onAPIError?.onError) {\n\t\t\t\toptions.onAPIError.onError(e, ctx);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst optLogLevel = options.logger?.level;\n\t\t\tconst log =\n\t\t\t\toptLogLevel === \"error\" ||\n\t\t\t\toptLogLevel === \"warn\" ||\n\t\t\t\toptLogLevel === \"debug\"\n\t\t\t\t\t? logger\n\t\t\t\t\t: undefined;\n\t\t\tif (options.logger?.disabled !== true) {\n\t\t\t\tif (\n\t\t\t\t\te &&\n\t\t\t\t\ttypeof e === \"object\" &&\n\t\t\t\t\t\"message\" in e &&\n\t\t\t\t\ttypeof e.message === \"string\"\n\t\t\t\t) {\n\t\t\t\t\tif (\n\t\t\t\t\t\te.message.includes(\"no column\") ||\n\t\t\t\t\t\te.message.includes(\"column\") ||\n\t\t\t\t\t\te.message.includes(\"relation\") ||\n\t\t\t\t\t\te.message.includes(\"table\") ||\n\t\t\t\t\t\te.message.includes(\"does not exist\")\n\t\t\t\t\t) {\n\t\t\t\t\t\tctx.logger?.error(e.message);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (e instanceof APIError) {\n\t\t\t\t\tif (e.status === \"INTERNAL_SERVER_ERROR\") {\n\t\t\t\t\t\tctx.logger.error(e.status, e);\n\t\t\t\t\t}\n\t\t\t\t\tlog?.error(e.message);\n\t\t\t\t} else {\n\t\t\t\t\tctx.logger?.error(\n\t\t\t\t\t\te && typeof e === \"object\" && \"name\" in e ? (e.name as string) : \"\",\n\t\t\t\t\t\te,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t});\n};\n\nexport {\n\ttype AuthEndpoint,\n\ttype AuthMiddleware,\n\tcreateAuthEndpoint,\n\tcreateAuthMiddleware,\n\toptionsMiddleware,\n} from \"@better-auth/core/api\";\nexport { APIError } from \"better-call\";\nexport { getIp } from \"../utils/get-request-ip\";\nexport * from \"./middlewares\";\nexport * from \"./routes\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,uBACf,SACA,UACC;CACD,MAAM,mCAAmB,IAAI,KAG1B;AAEH,SAAQ,SAAS,SAAS,WAAW;AACpC,MAAI,OAAO,WACV;QAAK,MA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AAI,QAAQ,YAAY,SAAS;AAChC,YAAQ,WAAW,QAAQ,GAAG,IAAI;AAClC;;GAGD,MAAM,cAAc,QAAQ,QAAQ;GACpC,MAAM,MACL,gBAAgB,WAChB,gBAAgB,UAChB,gBAAgB,UACb,SACA;AACJ,OAAI,QAAQ,QAAQ,aAAa,MAAM;AACtC,QACC,KACA,OAAO,MAAM,YACb,aAAa,KACb,OAAO,EAAE,YAAY,UAErB;SACC,EAAE,QAAQ,SAAS,YAAY,IAC/B,EAAE,QAAQ,SAAS,SAAS,IAC5B,EAAE,QAAQ,SAAS,WAAW,IAC9B,EAAE,QAAQ,SAAS,QAAQ,IAC3B,EAAE,QAAQ,SAAS,iBAAiB,EACnC;AACD,UAAI,QAAQ,MAAM,EAAE,QAAQ;AAC5B;;;AAIF,QAAI,aAAaA,YAAU;AAC1B,SAAI,EAAE,WAAW,wBAChB,KAAI,OAAO,MAAM,EAAE,QAAQ,EAAE;AAE9B,UAAK,MAAM,EAAE,QAAQ;UAErB,KAAI,QAAQ,MACX,KAAK,OAAO,MAAM,YAAY,UAAU,IAAK,EAAE,OAAkB,IACjE,EACA;;;EAIJ,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as _better_auth_core_oauth28 from "@better-auth/core/oauth2";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
-
import * as
|
|
3
|
+
import * as better_call694 from "better-call";
|
|
4
4
|
|
|
5
5
|
//#region src/api/routes/account.d.ts
|
|
6
|
-
declare const listUserAccounts:
|
|
6
|
+
declare const listUserAccounts: better_call694.StrictEndpoint<"/list-accounts", {
|
|
7
7
|
method: "GET";
|
|
8
|
-
use: ((inputContext:
|
|
8
|
+
use: ((inputContext: better_call694.MiddlewareInputContext<better_call694.MiddlewareOptions>) => Promise<{
|
|
9
9
|
session: {
|
|
10
10
|
session: Record<string, any> & {
|
|
11
11
|
id: string;
|
|
@@ -78,8 +78,6 @@ declare const listUserAccounts: better_call712.StrictEndpoint<"/list-accounts",
|
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
|
-
} & {
|
|
82
|
-
use: any[];
|
|
83
81
|
}, {
|
|
84
82
|
id: string;
|
|
85
83
|
providerId: string;
|
|
@@ -89,7 +87,7 @@ declare const listUserAccounts: better_call712.StrictEndpoint<"/list-accounts",
|
|
|
89
87
|
userId: string;
|
|
90
88
|
scopes: string[];
|
|
91
89
|
}[]>;
|
|
92
|
-
declare const linkSocialAccount:
|
|
90
|
+
declare const linkSocialAccount: better_call694.StrictEndpoint<"/link-social", {
|
|
93
91
|
method: "POST";
|
|
94
92
|
requireHeaders: true;
|
|
95
93
|
body: z.ZodObject<{
|
|
@@ -108,7 +106,7 @@ declare const linkSocialAccount: better_call712.StrictEndpoint<"/link-social", {
|
|
|
108
106
|
disableRedirect: z.ZodOptional<z.ZodBoolean>;
|
|
109
107
|
additionalData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
110
108
|
}, z.core.$strip>;
|
|
111
|
-
use: ((inputContext:
|
|
109
|
+
use: ((inputContext: better_call694.MiddlewareInputContext<better_call694.MiddlewareOptions>) => Promise<{
|
|
112
110
|
session: {
|
|
113
111
|
session: Record<string, any> & {
|
|
114
112
|
id: string;
|
|
@@ -163,19 +161,17 @@ declare const linkSocialAccount: better_call712.StrictEndpoint<"/link-social", {
|
|
|
163
161
|
};
|
|
164
162
|
};
|
|
165
163
|
};
|
|
166
|
-
} & {
|
|
167
|
-
use: any[];
|
|
168
164
|
}, {
|
|
169
165
|
url: string;
|
|
170
166
|
redirect: boolean;
|
|
171
167
|
}>;
|
|
172
|
-
declare const unlinkAccount:
|
|
168
|
+
declare const unlinkAccount: better_call694.StrictEndpoint<"/unlink-account", {
|
|
173
169
|
method: "POST";
|
|
174
170
|
body: z.ZodObject<{
|
|
175
171
|
providerId: z.ZodString;
|
|
176
172
|
accountId: z.ZodOptional<z.ZodString>;
|
|
177
173
|
}, z.core.$strip>;
|
|
178
|
-
use: ((inputContext:
|
|
174
|
+
use: ((inputContext: better_call694.MiddlewareInputContext<better_call694.MiddlewareOptions>) => Promise<{
|
|
179
175
|
session: {
|
|
180
176
|
session: Record<string, any> & {
|
|
181
177
|
id: string;
|
|
@@ -220,12 +216,10 @@ declare const unlinkAccount: better_call712.StrictEndpoint<"/unlink-account", {
|
|
|
220
216
|
};
|
|
221
217
|
};
|
|
222
218
|
};
|
|
223
|
-
} & {
|
|
224
|
-
use: any[];
|
|
225
219
|
}, {
|
|
226
220
|
status: boolean;
|
|
227
221
|
}>;
|
|
228
|
-
declare const getAccessToken:
|
|
222
|
+
declare const getAccessToken: better_call694.StrictEndpoint<"/get-access-token", {
|
|
229
223
|
method: "POST";
|
|
230
224
|
body: z.ZodObject<{
|
|
231
225
|
providerId: z.ZodString;
|
|
@@ -274,15 +268,13 @@ declare const getAccessToken: better_call712.StrictEndpoint<"/get-access-token",
|
|
|
274
268
|
};
|
|
275
269
|
};
|
|
276
270
|
};
|
|
277
|
-
} & {
|
|
278
|
-
use: any[];
|
|
279
271
|
}, {
|
|
280
272
|
accessToken: string;
|
|
281
273
|
accessTokenExpiresAt: Date | undefined;
|
|
282
274
|
scopes: string[];
|
|
283
275
|
idToken: string | undefined;
|
|
284
276
|
}>;
|
|
285
|
-
declare const refreshToken:
|
|
277
|
+
declare const refreshToken: better_call694.StrictEndpoint<"/refresh-token", {
|
|
286
278
|
method: "POST";
|
|
287
279
|
body: z.ZodObject<{
|
|
288
280
|
providerId: z.ZodString;
|
|
@@ -331,8 +323,6 @@ declare const refreshToken: better_call712.StrictEndpoint<"/refresh-token", {
|
|
|
331
323
|
};
|
|
332
324
|
};
|
|
333
325
|
};
|
|
334
|
-
} & {
|
|
335
|
-
use: any[];
|
|
336
326
|
}, {
|
|
337
327
|
accessToken: string | undefined;
|
|
338
328
|
refreshToken: string | undefined;
|
|
@@ -343,9 +333,9 @@ declare const refreshToken: better_call712.StrictEndpoint<"/refresh-token", {
|
|
|
343
333
|
providerId: string;
|
|
344
334
|
accountId: string;
|
|
345
335
|
}>;
|
|
346
|
-
declare const accountInfo:
|
|
336
|
+
declare const accountInfo: better_call694.StrictEndpoint<"/account-info", {
|
|
347
337
|
method: "GET";
|
|
348
|
-
use: ((inputContext:
|
|
338
|
+
use: ((inputContext: better_call694.MiddlewareInputContext<better_call694.MiddlewareOptions>) => Promise<{
|
|
349
339
|
session: {
|
|
350
340
|
session: Record<string, any> & {
|
|
351
341
|
id: string;
|
|
@@ -418,8 +408,6 @@ declare const accountInfo: better_call712.StrictEndpoint<"/account-info", {
|
|
|
418
408
|
query: z.ZodOptional<z.ZodObject<{
|
|
419
409
|
accountId: z.ZodOptional<z.ZodString>;
|
|
420
410
|
}, z.core.$strip>>;
|
|
421
|
-
} & {
|
|
422
|
-
use: any[];
|
|
423
411
|
}, {
|
|
424
412
|
user: _better_auth_core_oauth28.OAuth2UserInfo;
|
|
425
413
|
data: Record<string, any>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
import * as
|
|
2
|
+
import * as better_call693 from "better-call";
|
|
3
3
|
|
|
4
4
|
//#region src/api/routes/callback.d.ts
|
|
5
|
-
declare const callbackOAuth:
|
|
5
|
+
declare const callbackOAuth: better_call693.StrictEndpoint<"/callback/:id", {
|
|
6
6
|
method: ("GET" | "POST")[];
|
|
7
7
|
operationId: string;
|
|
8
8
|
body: z.ZodOptional<z.ZodObject<{
|
|
@@ -23,10 +23,8 @@ declare const callbackOAuth: better_call731.StrictEndpoint<"/callback/:id", {
|
|
|
23
23
|
}, z.core.$strip>>;
|
|
24
24
|
metadata: {
|
|
25
25
|
allowedMediaTypes: string[];
|
|
26
|
-
|
|
26
|
+
scope: "server";
|
|
27
27
|
};
|
|
28
|
-
} & {
|
|
29
|
-
use: any[];
|
|
30
28
|
}, void>;
|
|
31
29
|
//#endregion
|
|
32
30
|
export { callbackOAuth };
|
|
@@ -2,7 +2,7 @@ import { User } from "../../types/models.mjs";
|
|
|
2
2
|
import "../../types/index.mjs";
|
|
3
3
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
4
4
|
import * as z from "zod";
|
|
5
|
-
import * as
|
|
5
|
+
import * as better_call757 from "better-call";
|
|
6
6
|
|
|
7
7
|
//#region src/api/routes/email-verification.d.ts
|
|
8
8
|
declare function createEmailVerificationToken(secret: string, email: string,
|
|
@@ -22,7 +22,7 @@ extraPayload?: Record<string, any>): Promise<string>;
|
|
|
22
22
|
* A function to send a verification email to the user
|
|
23
23
|
*/
|
|
24
24
|
declare function sendVerificationEmailFn(ctx: GenericEndpointContext, user: User): Promise<void>;
|
|
25
|
-
declare const sendVerificationEmail:
|
|
25
|
+
declare const sendVerificationEmail: better_call757.StrictEndpoint<"/send-verification-email", {
|
|
26
26
|
method: "POST";
|
|
27
27
|
operationId: string;
|
|
28
28
|
body: z.ZodObject<{
|
|
@@ -94,19 +94,17 @@ declare const sendVerificationEmail: better_call753.StrictEndpoint<"/send-verifi
|
|
|
94
94
|
};
|
|
95
95
|
};
|
|
96
96
|
};
|
|
97
|
-
} & {
|
|
98
|
-
use: any[];
|
|
99
97
|
}, {
|
|
100
98
|
status: boolean;
|
|
101
99
|
}>;
|
|
102
|
-
declare const verifyEmail:
|
|
100
|
+
declare const verifyEmail: better_call757.StrictEndpoint<"/verify-email", {
|
|
103
101
|
method: "GET";
|
|
104
102
|
operationId: string;
|
|
105
103
|
query: z.ZodObject<{
|
|
106
104
|
token: z.ZodString;
|
|
107
105
|
callbackURL: z.ZodOptional<z.ZodString>;
|
|
108
106
|
}, z.core.$strip>;
|
|
109
|
-
use: ((inputContext:
|
|
107
|
+
use: ((inputContext: better_call757.MiddlewareInputContext<better_call757.MiddlewareOptions>) => Promise<void>)[];
|
|
110
108
|
metadata: {
|
|
111
109
|
openapi: {
|
|
112
110
|
description: string;
|
|
@@ -152,8 +150,6 @@ declare const verifyEmail: better_call753.StrictEndpoint<"/verify-email", {
|
|
|
152
150
|
};
|
|
153
151
|
};
|
|
154
152
|
};
|
|
155
|
-
} & {
|
|
156
|
-
use: any[];
|
|
157
153
|
}, void | {
|
|
158
154
|
status: boolean;
|
|
159
155
|
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as better_call750 from "better-call";
|
|
2
2
|
|
|
3
3
|
//#region src/api/routes/error.d.ts
|
|
4
|
-
declare const error:
|
|
4
|
+
declare const error: better_call750.StrictEndpoint<"/error", {
|
|
5
5
|
method: "GET";
|
|
6
6
|
metadata: {
|
|
7
7
|
openapi: {
|
|
@@ -20,10 +20,8 @@ declare const error: better_call759.StrictEndpoint<"/error", {
|
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
scope: "server";
|
|
24
24
|
};
|
|
25
|
-
} & {
|
|
26
|
-
use: any[];
|
|
27
25
|
}, Response>;
|
|
28
26
|
//#endregion
|
|
29
27
|
export { error };
|
package/dist/api/routes/ok.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as better_call761 from "better-call";
|
|
2
2
|
|
|
3
3
|
//#region src/api/routes/ok.d.ts
|
|
4
|
-
declare const ok:
|
|
4
|
+
declare const ok: better_call761.StrictEndpoint<"/ok", {
|
|
5
5
|
method: "GET";
|
|
6
6
|
metadata: {
|
|
7
7
|
openapi: {
|
|
@@ -26,10 +26,8 @@ declare const ok: better_call693.StrictEndpoint<"/ok", {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
scope: "server";
|
|
30
30
|
};
|
|
31
|
-
} & {
|
|
32
|
-
use: any[];
|
|
33
31
|
}, {
|
|
34
32
|
ok: boolean;
|
|
35
33
|
}>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
import * as
|
|
2
|
+
import * as better_call752 from "better-call";
|
|
3
3
|
|
|
4
4
|
//#region src/api/routes/reset-password.d.ts
|
|
5
|
-
declare const requestPasswordReset:
|
|
5
|
+
declare const requestPasswordReset: better_call752.StrictEndpoint<"/request-password-reset", {
|
|
6
6
|
method: "POST";
|
|
7
7
|
body: z.ZodObject<{
|
|
8
8
|
email: z.ZodEmail;
|
|
@@ -34,19 +34,17 @@ declare const requestPasswordReset: better_call726.StrictEndpoint<"/request-pass
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
-
} & {
|
|
38
|
-
use: any[];
|
|
39
37
|
}, {
|
|
40
38
|
status: boolean;
|
|
41
39
|
message: string;
|
|
42
40
|
}>;
|
|
43
|
-
declare const requestPasswordResetCallback:
|
|
41
|
+
declare const requestPasswordResetCallback: better_call752.StrictEndpoint<"/reset-password/:token", {
|
|
44
42
|
method: "GET";
|
|
45
43
|
operationId: string;
|
|
46
44
|
query: z.ZodObject<{
|
|
47
45
|
callbackURL: z.ZodString;
|
|
48
46
|
}, z.core.$strip>;
|
|
49
|
-
use: ((inputContext:
|
|
47
|
+
use: ((inputContext: better_call752.MiddlewareInputContext<better_call752.MiddlewareOptions>) => Promise<void>)[];
|
|
50
48
|
metadata: {
|
|
51
49
|
openapi: {
|
|
52
50
|
operationId: string;
|
|
@@ -87,10 +85,8 @@ declare const requestPasswordResetCallback: better_call726.StrictEndpoint<"/rese
|
|
|
87
85
|
};
|
|
88
86
|
};
|
|
89
87
|
};
|
|
90
|
-
} & {
|
|
91
|
-
use: any[];
|
|
92
88
|
}, never>;
|
|
93
|
-
declare const resetPassword:
|
|
89
|
+
declare const resetPassword: better_call752.StrictEndpoint<"/reset-password", {
|
|
94
90
|
method: "POST";
|
|
95
91
|
operationId: string;
|
|
96
92
|
query: z.ZodOptional<z.ZodObject<{
|
|
@@ -123,8 +119,6 @@ declare const resetPassword: better_call726.StrictEndpoint<"/reset-password", {
|
|
|
123
119
|
};
|
|
124
120
|
};
|
|
125
121
|
};
|
|
126
|
-
} & {
|
|
127
|
-
use: any[];
|
|
128
122
|
}, {
|
|
129
123
|
status: boolean;
|
|
130
124
|
}>;
|
|
@@ -3,10 +3,10 @@ import { InferSession, InferUser, Session, User } from "../../types/models.mjs";
|
|
|
3
3
|
import "../../types/index.mjs";
|
|
4
4
|
import { BetterAuthOptions, GenericEndpointContext } from "@better-auth/core";
|
|
5
5
|
import * as z from "zod";
|
|
6
|
-
import * as
|
|
6
|
+
import * as better_call728 from "better-call";
|
|
7
7
|
|
|
8
8
|
//#region src/api/routes/session.d.ts
|
|
9
|
-
declare const getSession: <Option extends BetterAuthOptions>() =>
|
|
9
|
+
declare const getSession: <Option extends BetterAuthOptions>() => better_call728.StrictEndpoint<"/get-session", {
|
|
10
10
|
method: "GET";
|
|
11
11
|
operationId: string;
|
|
12
12
|
query: z.ZodOptional<z.ZodObject<{
|
|
@@ -42,8 +42,6 @@ declare const getSession: <Option extends BetterAuthOptions>() => better_call732
|
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
|
-
} & {
|
|
46
|
-
use: any[];
|
|
47
45
|
}, {
|
|
48
46
|
session: InferSession<Option>;
|
|
49
47
|
user: InferUser<Option>;
|
|
@@ -58,7 +56,7 @@ declare const getSessionFromCtx: <U extends Record<string, any> = Record<string,
|
|
|
58
56
|
/**
|
|
59
57
|
* The middleware forces the endpoint to require a valid session.
|
|
60
58
|
*/
|
|
61
|
-
declare const sessionMiddleware: (inputContext:
|
|
59
|
+
declare const sessionMiddleware: (inputContext: better_call728.MiddlewareInputContext<better_call728.MiddlewareOptions>) => Promise<{
|
|
62
60
|
session: {
|
|
63
61
|
session: Record<string, any> & {
|
|
64
62
|
id: string;
|
|
@@ -86,7 +84,7 @@ declare const sessionMiddleware: (inputContext: better_call732.MiddlewareInputCo
|
|
|
86
84
|
* This should be used for sensitive operations like password changes, account deletion, etc.
|
|
87
85
|
* to ensure that revoked sessions cannot be used even if they're still cached in cookies.
|
|
88
86
|
*/
|
|
89
|
-
declare const sensitiveSessionMiddleware: (inputContext:
|
|
87
|
+
declare const sensitiveSessionMiddleware: (inputContext: better_call728.MiddlewareInputContext<better_call728.MiddlewareOptions>) => Promise<{
|
|
90
88
|
session: {
|
|
91
89
|
session: Record<string, any> & {
|
|
92
90
|
id: string;
|
|
@@ -113,7 +111,7 @@ declare const sensitiveSessionMiddleware: (inputContext: better_call732.Middlewa
|
|
|
113
111
|
* This middleware allows you to call the endpoint on the client if session is valid.
|
|
114
112
|
* However, if called on the server, no session is required.
|
|
115
113
|
*/
|
|
116
|
-
declare const requestOnlySessionMiddleware: (inputContext:
|
|
114
|
+
declare const requestOnlySessionMiddleware: (inputContext: better_call728.MiddlewareInputContext<better_call728.MiddlewareOptions>) => Promise<{
|
|
117
115
|
session: {
|
|
118
116
|
session: Record<string, any> & {
|
|
119
117
|
id: string;
|
|
@@ -143,7 +141,7 @@ declare const requestOnlySessionMiddleware: (inputContext: better_call732.Middle
|
|
|
143
141
|
* Session freshness check will be skipped if the session config's freshAge
|
|
144
142
|
* is set to 0
|
|
145
143
|
*/
|
|
146
|
-
declare const freshSessionMiddleware: (inputContext:
|
|
144
|
+
declare const freshSessionMiddleware: (inputContext: better_call728.MiddlewareInputContext<better_call728.MiddlewareOptions>) => Promise<{
|
|
147
145
|
session: {
|
|
148
146
|
session: Record<string, any> & {
|
|
149
147
|
id: string;
|
|
@@ -169,10 +167,10 @@ declare const freshSessionMiddleware: (inputContext: better_call732.MiddlewareIn
|
|
|
169
167
|
/**
|
|
170
168
|
* user active sessions list
|
|
171
169
|
*/
|
|
172
|
-
declare const listSessions: <Option extends BetterAuthOptions>() =>
|
|
170
|
+
declare const listSessions: <Option extends BetterAuthOptions>() => better_call728.StrictEndpoint<"/list-sessions", {
|
|
173
171
|
method: "GET";
|
|
174
172
|
operationId: string;
|
|
175
|
-
use: ((inputContext:
|
|
173
|
+
use: ((inputContext: better_call728.MiddlewareInputContext<better_call728.MiddlewareOptions>) => Promise<{
|
|
176
174
|
session: {
|
|
177
175
|
session: Record<string, any> & {
|
|
178
176
|
id: string;
|
|
@@ -217,18 +215,18 @@ declare const listSessions: <Option extends BetterAuthOptions>() => better_call7
|
|
|
217
215
|
};
|
|
218
216
|
};
|
|
219
217
|
};
|
|
220
|
-
} & {
|
|
221
|
-
|
|
222
|
-
}
|
|
218
|
+
}, Prettify$1<InferSession<Option> & {
|
|
219
|
+
token: undefined;
|
|
220
|
+
}>[]>;
|
|
223
221
|
/**
|
|
224
222
|
* revoke a single session
|
|
225
223
|
*/
|
|
226
|
-
declare const revokeSession:
|
|
224
|
+
declare const revokeSession: better_call728.StrictEndpoint<"/revoke-session", {
|
|
227
225
|
method: "POST";
|
|
228
226
|
body: z.ZodObject<{
|
|
229
227
|
token: z.ZodString;
|
|
230
228
|
}, z.core.$strip>;
|
|
231
|
-
use: ((inputContext:
|
|
229
|
+
use: ((inputContext: better_call728.MiddlewareInputContext<better_call728.MiddlewareOptions>) => Promise<{
|
|
232
230
|
session: {
|
|
233
231
|
session: Record<string, any> & {
|
|
234
232
|
id: string;
|
|
@@ -292,17 +290,15 @@ declare const revokeSession: better_call732.StrictEndpoint<"/revoke-session", {
|
|
|
292
290
|
};
|
|
293
291
|
};
|
|
294
292
|
};
|
|
295
|
-
} & {
|
|
296
|
-
use: any[];
|
|
297
293
|
}, {
|
|
298
294
|
status: boolean;
|
|
299
295
|
}>;
|
|
300
296
|
/**
|
|
301
297
|
* revoke all user sessions
|
|
302
298
|
*/
|
|
303
|
-
declare const revokeSessions:
|
|
299
|
+
declare const revokeSessions: better_call728.StrictEndpoint<"/revoke-sessions", {
|
|
304
300
|
method: "POST";
|
|
305
|
-
use: ((inputContext:
|
|
301
|
+
use: ((inputContext: better_call728.MiddlewareInputContext<better_call728.MiddlewareOptions>) => Promise<{
|
|
306
302
|
session: {
|
|
307
303
|
session: Record<string, any> & {
|
|
308
304
|
id: string;
|
|
@@ -350,15 +346,13 @@ declare const revokeSessions: better_call732.StrictEndpoint<"/revoke-sessions",
|
|
|
350
346
|
};
|
|
351
347
|
};
|
|
352
348
|
};
|
|
353
|
-
} & {
|
|
354
|
-
use: any[];
|
|
355
349
|
}, {
|
|
356
350
|
status: boolean;
|
|
357
351
|
}>;
|
|
358
|
-
declare const revokeOtherSessions:
|
|
352
|
+
declare const revokeOtherSessions: better_call728.StrictEndpoint<"/revoke-other-sessions", {
|
|
359
353
|
method: "POST";
|
|
360
354
|
requireHeaders: true;
|
|
361
|
-
use: ((inputContext:
|
|
355
|
+
use: ((inputContext: better_call728.MiddlewareInputContext<better_call728.MiddlewareOptions>) => Promise<{
|
|
362
356
|
session: {
|
|
363
357
|
session: Record<string, any> & {
|
|
364
358
|
id: string;
|
|
@@ -405,8 +399,6 @@ declare const revokeOtherSessions: better_call732.StrictEndpoint<"/revoke-other-
|
|
|
405
399
|
};
|
|
406
400
|
};
|
|
407
401
|
};
|
|
408
|
-
} & {
|
|
409
|
-
use: any[];
|
|
410
402
|
}, {
|
|
411
403
|
status: boolean;
|
|
412
404
|
}>;
|
|
@@ -311,6 +311,14 @@ const listSessions = () => createAuthEndpoint("/list-sessions", {
|
|
|
311
311
|
try {
|
|
312
312
|
const activeSessions = (await ctx.context.internalAdapter.listSessions(ctx.context.session.user.id)).filter((session) => {
|
|
313
313
|
return session.expiresAt > /* @__PURE__ */ new Date();
|
|
314
|
+
}).map((session) => {
|
|
315
|
+
return {
|
|
316
|
+
...session,
|
|
317
|
+
token: void 0,
|
|
318
|
+
expiresAt: session.expiresAt.toISOString(),
|
|
319
|
+
createdAt: session.createdAt.toISOString(),
|
|
320
|
+
updatedAt: session.updatedAt.toISOString()
|
|
321
|
+
};
|
|
314
322
|
});
|
|
315
323
|
return ctx.json(activeSessions);
|
|
316
324
|
} catch (e) {
|