better-auth 1.4.18 → 1.4.19
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/adapters/drizzle-adapter/drizzle-adapter.mjs +37 -5
- package/dist/adapters/drizzle-adapter/drizzle-adapter.mjs.map +1 -1
- package/dist/adapters/kysely-adapter/kysely-adapter.mjs +13 -3
- package/dist/adapters/kysely-adapter/kysely-adapter.mjs.map +1 -1
- package/dist/adapters/memory-adapter/memory-adapter.mjs +21 -17
- package/dist/adapters/memory-adapter/memory-adapter.mjs.map +1 -1
- package/dist/adapters/mongodb-adapter/mongodb-adapter.mjs +12 -1
- package/dist/adapters/mongodb-adapter/mongodb-adapter.mjs.map +1 -1
- package/dist/adapters/prisma-adapter/prisma-adapter.mjs +2 -2
- package/dist/adapters/prisma-adapter/prisma-adapter.mjs.map +1 -1
- package/dist/api/index.d.mts +407 -407
- package/dist/api/routes/account.d.mts +11 -11
- package/dist/api/routes/account.mjs +1 -1
- package/dist/api/routes/account.mjs.map +1 -1
- package/dist/api/routes/callback.d.mts +2 -2
- package/dist/api/routes/callback.mjs +1 -1
- package/dist/api/routes/callback.mjs.map +1 -1
- package/dist/api/routes/email-verification.d.mts +4 -4
- package/dist/api/routes/email-verification.mjs +1 -1
- package/dist/api/routes/email-verification.mjs.map +1 -1
- package/dist/api/routes/error.d.mts +2 -2
- package/dist/api/routes/ok.d.mts +2 -2
- package/dist/api/routes/password.d.mts +7 -7
- package/dist/api/routes/session.d.mts +14 -14
- package/dist/api/routes/sign-in.d.mts +4 -4
- package/dist/api/routes/sign-out.d.mts +2 -2
- package/dist/api/routes/sign-up.d.mts +3 -3
- package/dist/api/routes/update-user.d.mts +13 -13
- package/dist/api/routes/update-user.mjs +1 -1
- package/dist/api/routes/update-user.mjs.map +1 -1
- package/dist/client/react/index.d.mts +13 -13
- package/dist/client/svelte/index.d.mts +15 -15
- package/dist/client/vanilla.d.mts +15 -15
- package/dist/client/vue/index.d.mts +15 -15
- package/dist/context/create-context.mjs +1 -1
- package/dist/context/create-context.mjs.map +1 -1
- package/dist/cookies/index.d.mts +6 -6
- package/dist/cookies/index.mjs +5 -8
- package/dist/cookies/index.mjs.map +1 -1
- package/dist/db/field.d.mts +10 -10
- package/dist/db/field.mjs.map +1 -1
- package/dist/db/internal-adapter.mjs +1 -1
- package/dist/db/internal-adapter.mjs.map +1 -1
- package/dist/integrations/next-js.d.mts +4 -4
- package/dist/integrations/svelte-kit.d.mts +2 -2
- package/dist/integrations/tanstack-start-solid.d.mts +4 -4
- package/dist/integrations/tanstack-start.d.mts +4 -4
- package/dist/plugins/access/types.d.mts +1 -1
- package/dist/plugins/admin/admin.d.mts +114 -119
- package/dist/plugins/admin/admin.mjs +1 -1
- package/dist/plugins/admin/admin.mjs.map +1 -1
- package/dist/plugins/admin/routes.mjs +1 -1
- package/dist/plugins/admin/routes.mjs.map +1 -1
- package/dist/plugins/anonymous/index.d.mts +7 -7
- package/dist/plugins/api-key/index.d.mts +95 -80
- package/dist/plugins/api-key/routes/verify-api-key.mjs +1 -0
- 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 +5 -5
- package/dist/plugins/custom-session/index.mjs +13 -5
- package/dist/plugins/custom-session/index.mjs.map +1 -1
- package/dist/plugins/device-authorization/index.d.mts +6 -6
- package/dist/plugins/email-otp/index.d.mts +16 -16
- package/dist/plugins/email-otp/routes.mjs +1 -1
- package/dist/plugins/email-otp/routes.mjs.map +1 -1
- package/dist/plugins/generic-oauth/error-codes.mjs +3 -1
- package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -1
- package/dist/plugins/generic-oauth/index.d.mts +32 -29
- package/dist/plugins/generic-oauth/index.mjs +8 -0
- package/dist/plugins/generic-oauth/index.mjs.map +1 -1
- package/dist/plugins/generic-oauth/routes.mjs +19 -2
- package/dist/plugins/generic-oauth/routes.mjs.map +1 -1
- package/dist/plugins/generic-oauth/types.d.mts +14 -0
- 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 +9 -9
- package/dist/plugins/last-login-method/index.d.mts +4 -4
- package/dist/plugins/magic-link/index.d.mts +4 -4
- package/dist/plugins/mcp/authorize.mjs +1 -1
- package/dist/plugins/mcp/authorize.mjs.map +1 -1
- package/dist/plugins/mcp/index.d.mts +10 -10
- package/dist/plugins/multi-session/index.d.mts +9 -9
- package/dist/plugins/oauth-proxy/index.d.mts +8 -8
- package/dist/plugins/oidc-provider/authorize.mjs +1 -1
- package/dist/plugins/oidc-provider/authorize.mjs.map +1 -1
- package/dist/plugins/oidc-provider/index.d.mts +15 -15
- package/dist/plugins/one-tap/client.d.mts +5 -5
- package/dist/plugins/one-tap/index.d.mts +2 -2
- package/dist/plugins/one-time-token/index.d.mts +5 -5
- package/dist/plugins/open-api/index.d.mts +3 -3
- package/dist/plugins/organization/client.d.mts +9 -9
- package/dist/plugins/organization/error-codes.d.mts +1 -0
- package/dist/plugins/organization/error-codes.mjs +2 -1
- package/dist/plugins/organization/error-codes.mjs.map +1 -1
- package/dist/plugins/organization/organization.d.mts +4 -4
- package/dist/plugins/organization/routes/crud-access-control.d.mts +22 -22
- package/dist/plugins/organization/routes/crud-access-control.mjs +22 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -1
- package/dist/plugins/organization/routes/crud-invites.d.mts +70 -70
- package/dist/plugins/organization/routes/crud-invites.mjs +0 -4
- package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -1
- package/dist/plugins/organization/routes/crud-members.d.mts +67 -67
- package/dist/plugins/organization/routes/crud-org.d.mts +59 -59
- package/dist/plugins/organization/routes/crud-team.d.mts +79 -79
- package/dist/plugins/phone-number/index.d.mts +33 -33
- package/dist/plugins/phone-number/routes.mjs +6 -2
- package/dist/plugins/phone-number/routes.mjs.map +1 -1
- package/dist/plugins/siwe/index.d.mts +3 -3
- package/dist/plugins/two-factor/backup-codes/index.d.mts +5 -5
- package/dist/plugins/two-factor/client.d.mts +2 -2
- package/dist/plugins/two-factor/index.d.mts +18 -18
- package/dist/plugins/two-factor/otp/index.d.mts +3 -3
- package/dist/plugins/two-factor/totp/index.d.mts +5 -5
- package/dist/plugins/username/index.d.mts +12 -12
- package/dist/plugins/username/schema.d.mts +3 -3
- package/dist/test-utils/test-instance.d.mts +1242 -1242
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.mjs","names":["user"],"sources":["../../../src/plugins/phone-number/routes.ts"],"sourcesContent":["import { createAuthEndpoint } from \"@better-auth/core/api\";\nimport { BASE_ERROR_CODES } from \"@better-auth/core/error\";\nimport { APIError } from \"better-call\";\nimport * as z from \"zod\";\nimport { getSessionFromCtx } from \"../../api\";\nimport { setSessionCookie } from \"../../cookies\";\nimport { generateRandomString } from \"../../crypto/random\";\nimport { parseUserOutput } from \"../../db/schema\";\nimport type { User } from \"../../types\";\nimport { getDate } from \"../../utils/date\";\nimport { PHONE_NUMBER_ERROR_CODES } from \"./error-codes\";\nimport type { PhoneNumberOptions, UserWithPhoneNumber } from \"./types\";\n\nexport type RequiredPhoneNumberOptions = PhoneNumberOptions & {\n\texpiresIn: number;\n\totpLength: number;\n\tphoneNumber: string;\n\tphoneNumberVerified: string;\n\tcode: string;\n\tcreatedAt: string;\n};\n\nconst signInPhoneNumberBodySchema = z.object({\n\tphoneNumber: z.string().meta({\n\t\tdescription: 'Phone number to sign in. Eg: \"+1234567890\"',\n\t}),\n\tpassword: z.string().meta({\n\t\tdescription: \"Password to use for sign in.\",\n\t}),\n\trememberMe: z\n\t\t.boolean()\n\t\t.meta({\n\t\t\tdescription: \"Remember the session. Eg: true\",\n\t\t})\n\t\t.optional(),\n});\n\n/**\n * ### Endpoint\n *\n * POST `/sign-in/phone-number`\n *\n * ### API Methods\n *\n * **server:**\n * `auth.api.signInPhoneNumber`\n *\n * **client:**\n * `authClient.signIn.phoneNumber`\n *\n * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/phone-number#api-method-sign-in-phone-number)\n */\nexport const signInPhoneNumber = (opts: RequiredPhoneNumberOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/sign-in/phone-number\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: signInPhoneNumberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tsummary: \"Sign in with phone number\",\n\t\t\t\t\tdescription: \"Use this endpoint to sign in with phone number\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t200: {\n\t\t\t\t\t\t\tdescription: \"Success\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tuser: {\n\t\t\t\t\t\t\t\t\t\t\t\t$ref: \"#/components/schemas/User\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tsession: {\n\t\t\t\t\t\t\t\t\t\t\t\t$ref: \"#/components/schemas/Session\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\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\t400: {\n\t\t\t\t\t\t\tdescription: \"Invalid phone number or password\",\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},\n\t\tasync (ctx) => {\n\t\t\tconst { password, phoneNumber } = ctx.body;\n\n\t\t\tif (opts.phoneNumberValidator) {\n\t\t\t\tconst isValidNumber = await opts.phoneNumberValidator(\n\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t);\n\t\t\t\tif (!isValidNumber) {\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst user = await ctx.context.adapter.findOne<UserWithPhoneNumber>({\n\t\t\t\tmodel: \"user\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"phoneNumber\",\n\t\t\t\t\t\tvalue: phoneNumber,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) {\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER_OR_PASSWORD,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (opts.requireVerification) {\n\t\t\t\tif (!user.phoneNumberVerified) {\n\t\t\t\t\tconst otp = generateOTP(opts.otpLength);\n\t\t\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\t\t\tvalue: otp,\n\t\t\t\t\t\tidentifier: phoneNumber,\n\t\t\t\t\t\texpiresAt: getDate(opts.expiresIn, \"sec\"),\n\t\t\t\t\t});\n\t\t\t\t\tif (opts.sendOTP) {\n\t\t\t\t\t\tawait ctx.context.runInBackgroundOrAwait(\n\t\t\t\t\t\t\topts.sendOTP(\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tphoneNumber,\n\t\t\t\t\t\t\t\t\tcode: otp,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tctx,\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\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.PHONE_NUMBER_NOT_VERIFIED,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst accounts = await ctx.context.internalAdapter.findAccountByUserId(\n\t\t\t\tuser.id,\n\t\t\t);\n\t\t\tconst credentialAccount = accounts.find(\n\t\t\t\t(a) => a.providerId === \"credential\",\n\t\t\t);\n\t\t\tif (!credentialAccount) {\n\t\t\t\tctx.context.logger.error(\"Credential account not found\", {\n\t\t\t\t\tphoneNumber,\n\t\t\t\t});\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER_OR_PASSWORD,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst currentPassword = credentialAccount?.password;\n\t\t\tif (!currentPassword) {\n\t\t\t\tctx.context.logger.error(\"Password not found\", { phoneNumber });\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.UNEXPECTED_ERROR,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst validPassword = await ctx.context.password.verify({\n\t\t\t\thash: currentPassword,\n\t\t\t\tpassword,\n\t\t\t});\n\t\t\tif (!validPassword) {\n\t\t\t\tctx.context.logger.error(\"Invalid password\");\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER_OR_PASSWORD,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\t\tuser.id,\n\t\t\t\tctx.body.rememberMe === false,\n\t\t\t);\n\t\t\tif (!session) {\n\t\t\t\tctx.context.logger.error(\"Failed to create session\");\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait setSessionCookie(\n\t\t\t\tctx,\n\t\t\t\t{\n\t\t\t\t\tsession,\n\t\t\t\t\tuser: user,\n\t\t\t\t},\n\t\t\t\tctx.body.rememberMe === false,\n\t\t\t);\n\t\t\treturn ctx.json({\n\t\t\t\ttoken: session.token,\n\t\t\t\tuser: parseUserOutput(ctx.context.options, user),\n\t\t\t});\n\t\t},\n\t);\n\nconst sendPhoneNumberOTPBodySchema = z.object({\n\tphoneNumber: z.string().meta({\n\t\tdescription: 'Phone number to send OTP. Eg: \"+1234567890\"',\n\t}),\n});\n\n/**\n * ### Endpoint\n *\n * POST `/phone-number/send-otp`\n *\n * ### API Methods\n *\n * **server:**\n * `auth.api.sendPhoneNumberOTP`\n *\n * **client:**\n * `authClient.phoneNumber.sendOtp`\n *\n * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/phone-number#api-method-phone-number-send-otp)\n */\nexport const sendPhoneNumberOTP = (opts: RequiredPhoneNumberOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/phone-number/send-otp\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: sendPhoneNumberOTPBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tsummary: \"Send OTP to phone number\",\n\t\t\t\t\tdescription: \"Use this endpoint to send OTP to phone number\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t200: {\n\t\t\t\t\t\t\tdescription: \"Success\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\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},\n\t\tasync (ctx) => {\n\t\t\tif (!opts?.sendOTP) {\n\t\t\t\tctx.context.logger.warn(\"sendOTP not implemented\");\n\t\t\t\tthrow new APIError(\"NOT_IMPLEMENTED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.SEND_OTP_NOT_IMPLEMENTED,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (opts.phoneNumberValidator) {\n\t\t\t\tconst isValidNumber = await opts.phoneNumberValidator(\n\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t);\n\t\t\t\tif (!isValidNumber) {\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst code = generateOTP(opts.otpLength);\n\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\tvalue: `${code}:0`,\n\t\t\t\tidentifier: ctx.body.phoneNumber,\n\t\t\t\texpiresAt: getDate(opts.expiresIn, \"sec\"),\n\t\t\t});\n\t\t\tawait ctx.context.runInBackgroundOrAwait(\n\t\t\t\topts.sendOTP(\n\t\t\t\t\t{\n\t\t\t\t\t\tphoneNumber: ctx.body.phoneNumber,\n\t\t\t\t\t\tcode,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn ctx.json({ message: \"code sent\" });\n\t\t},\n\t);\n\nconst verifyPhoneNumberBodySchema = z.object({\n\t/**\n\t * Phone number\n\t */\n\tphoneNumber: z.string().meta({\n\t\tdescription: 'Phone number to verify. Eg: \"+1234567890\"',\n\t}),\n\t/**\n\t * OTP code\n\t */\n\tcode: z.string().meta({\n\t\tdescription: 'OTP code. Eg: \"123456\"',\n\t}),\n\t/**\n\t * Disable session creation after verification\n\t * @default false\n\t */\n\tdisableSession: z\n\t\t.boolean()\n\t\t.meta({\n\t\t\tdescription: \"Disable session creation after verification. Eg: false\",\n\t\t})\n\t\t.optional(),\n\t/**\n\t * This checks if there is a session already\n\t * and updates the phone number with the provided\n\t * phone number\n\t */\n\tupdatePhoneNumber: z\n\t\t.boolean()\n\t\t.meta({\n\t\t\tdescription:\n\t\t\t\t\"Check if there is a session and update the phone number. Eg: true\",\n\t\t})\n\t\t.optional(),\n});\n\n/**\n * ### Endpoint\n *\n * POST `/phone-number/verify`\n *\n * ### API Methods\n *\n * **server:**\n * `auth.api.verifyPhoneNumber`\n *\n * **client:**\n * `authClient.phoneNumber.verify`\n *\n * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/phone-number#api-method-phone-number-verify)\n */\nexport const verifyPhoneNumber = (opts: RequiredPhoneNumberOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/phone-number/verify\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: verifyPhoneNumberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tsummary: \"Verify phone number\",\n\t\t\t\t\tdescription: \"Use this endpoint to verify phone number\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Phone number verified successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Indicates if the verification was successful\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [true],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\ttoken: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Session token if session is created, null if disableSession is true or no session is created\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tuser: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the user\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\temail: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"email\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"User's email address\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\temailVerified: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Whether the email is verified\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tname: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"User's name\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\timage: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"uri\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"User's profile image URL\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tphoneNumber: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"User's phone number\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tphoneNumberVerified: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Whether the phone number is verified\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the user was created\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tupdatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"Timestamp when the user was last updated\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\trequired: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"phoneNumber\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"phoneNumberVerified\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"createdAt\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"updatedAt\",\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"User object with phone number details, null if no user is created or found\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"status\"],\n\t\t\t\t\t\t\t\t\t},\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\t400: {\n\t\t\t\t\t\t\tdescription: \"Invalid OTP\",\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},\n\t\tasync (ctx) => {\n\t\t\tif (opts?.verifyOTP) {\n\t\t\t\t// Use custom verifyOTP if provided\n\t\t\t\tconst isValid = await opts.verifyOTP(\n\t\t\t\t\t{\n\t\t\t\t\t\tphoneNumber: ctx.body.phoneNumber,\n\t\t\t\t\t\tcode: ctx.body.code,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t);\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_OTP,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Clean up verification value\n\t\t\t\tconst otp = await ctx.context.internalAdapter.findVerificationValue(\n\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t);\n\t\t\t\tif (otp) {\n\t\t\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(otp.id);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Default internal verification logic\n\t\t\t\tconst otp = await ctx.context.internalAdapter.findVerificationValue(\n\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t);\n\n\t\t\t\tif (!otp || otp.expiresAt < new Date()) {\n\t\t\t\t\tif (otp && otp.expiresAt < new Date()) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.OTP_EXPIRED,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.OTP_NOT_FOUND,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst [otpValue, attempts] = otp.value.split(\":\");\n\t\t\t\tconst allowedAttempts = opts?.allowedAttempts || 3;\n\t\t\t\tif (attempts && parseInt(attempts) >= allowedAttempts) {\n\t\t\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(otp.id);\n\t\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.TOO_MANY_ATTEMPTS,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (otpValue !== ctx.body.code) {\n\t\t\t\t\tawait ctx.context.internalAdapter.updateVerificationValue(otp.id, {\n\t\t\t\t\t\tvalue: `${otpValue}:${parseInt(attempts || \"0\") + 1}`,\n\t\t\t\t\t});\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_OTP,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(otp.id);\n\t\t\t}\n\n\t\t\tif (ctx.body.updatePhoneNumber) {\n\t\t\t\tconst session = await getSessionFromCtx(ctx);\n\t\t\t\tif (!session) {\n\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\tmessage: BASE_ERROR_CODES.USER_NOT_FOUND,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst existingUser =\n\t\t\t\t\tawait ctx.context.adapter.findMany<UserWithPhoneNumber>({\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tfield: \"phoneNumber\",\n\t\t\t\t\t\t\t\tvalue: ctx.body.phoneNumber,\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\tif (existingUser.length) {\n\t\t\t\t\tthrow ctx.error(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.PHONE_NUMBER_EXIST,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst user =\n\t\t\t\t\tawait ctx.context.internalAdapter.updateUser<UserWithPhoneNumber>(\n\t\t\t\t\t\tsession.user.id,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[opts.phoneNumber]: ctx.body.phoneNumber,\n\t\t\t\t\t\t\t[opts.phoneNumberVerified]: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\treturn ctx.json({\n\t\t\t\t\tstatus: true,\n\t\t\t\t\ttoken: session.session.token,\n\t\t\t\t\tuser: parseUserOutput(ctx.context.options, user),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet user = await ctx.context.adapter.findOne<UserWithPhoneNumber>({\n\t\t\t\tmodel: \"user\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: ctx.body.phoneNumber,\n\t\t\t\t\t\tfield: opts.phoneNumber,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) {\n\t\t\t\tif (opts?.signUpOnVerification) {\n\t\t\t\t\tuser =\n\t\t\t\t\t\tawait ctx.context.internalAdapter.createUser<UserWithPhoneNumber>({\n\t\t\t\t\t\t\temail: opts.signUpOnVerification.getTempEmail(\n\t\t\t\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tname: opts.signUpOnVerification.getTempName\n\t\t\t\t\t\t\t\t? opts.signUpOnVerification.getTempName(ctx.body.phoneNumber)\n\t\t\t\t\t\t\t\t: ctx.body.phoneNumber,\n\t\t\t\t\t\t\t[opts.phoneNumber]: ctx.body.phoneNumber,\n\t\t\t\t\t\t\t[opts.phoneNumberVerified]: true,\n\t\t\t\t\t\t});\n\t\t\t\t\tif (!user) {\n\t\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\t\tmessage: BASE_ERROR_CODES.FAILED_TO_CREATE_USER,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tuser =\n\t\t\t\t\tawait ctx.context.internalAdapter.updateUser<UserWithPhoneNumber>(\n\t\t\t\t\t\tuser.id,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[opts.phoneNumberVerified]: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t}\n\t\t\tif (!user) {\n\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\tmessage: BASE_ERROR_CODES.FAILED_TO_UPDATE_USER,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait opts?.callbackOnVerification?.(\n\t\t\t\t{\n\t\t\t\t\tphoneNumber: ctx.body.phoneNumber,\n\t\t\t\t\tuser,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tif (!ctx.body.disableSession) {\n\t\t\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\t\t\tuser.id,\n\t\t\t\t);\n\t\t\t\tif (!session) {\n\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\tmessage: BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tawait setSessionCookie(ctx, {\n\t\t\t\t\tsession,\n\t\t\t\t\tuser,\n\t\t\t\t});\n\t\t\t\treturn ctx.json({\n\t\t\t\t\tstatus: true,\n\t\t\t\t\ttoken: session.token,\n\t\t\t\t\tuser: parseUserOutput(ctx.context.options, user),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json({\n\t\t\t\tstatus: true,\n\t\t\t\ttoken: null,\n\t\t\t\tuser: parseUserOutput(ctx.context.options, user),\n\t\t\t});\n\t\t},\n\t);\n\nconst requestPasswordResetPhoneNumberBodySchema = z.object({\n\tphoneNumber: z.string(),\n});\n\nexport const requestPasswordResetPhoneNumber = (\n\topts: RequiredPhoneNumberOptions,\n) =>\n\tcreateAuthEndpoint(\n\t\t\"/phone-number/request-password-reset\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: requestPasswordResetPhoneNumberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Request OTP for password reset via phone number\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"OTP sent successfully for password reset\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Indicates if the OTP was sent successfully\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [true],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"status\"],\n\t\t\t\t\t\t\t\t\t},\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},\n\t\tasync (ctx) => {\n\t\t\tconst user = await ctx.context.adapter.findOne<UserWithPhoneNumber>({\n\t\t\t\tmodel: \"user\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: ctx.body.phoneNumber,\n\t\t\t\t\t\tfield: opts.phoneNumber,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tconst code = generateOTP(opts.otpLength);\n\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\tvalue: `${code}:0`,\n\t\t\t\tidentifier: `${ctx.body.phoneNumber}-request-password-reset`,\n\t\t\t\texpiresAt: getDate(opts.expiresIn, \"sec\"),\n\t\t\t});\n\t\t\t// to avoid leaking the existence of the phone number\n\t\t\tif (!user) {\n\t\t\t\treturn ctx.json({\n\t\t\t\t\tstatus: true,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (opts.sendPasswordResetOTP) {\n\t\t\t\tawait ctx.context.runInBackgroundOrAwait(\n\t\t\t\t\topts.sendPasswordResetOTP(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tphoneNumber: ctx.body.phoneNumber,\n\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tctx,\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});\n\t\t},\n\t);\n\nconst resetPasswordPhoneNumberBodySchema = z.object({\n\totp: z.string().meta({\n\t\tdescription: 'The one time password to reset the password. Eg: \"123456\"',\n\t}),\n\tphoneNumber: z.string().meta({\n\t\tdescription:\n\t\t\t'The phone number to the account which intends to reset the password for. Eg: \"+1234567890\"',\n\t}),\n\tnewPassword: z.string().meta({\n\t\tdescription: `The new password. Eg: \"new-and-secure-password\"`,\n\t}),\n});\n\nexport const resetPasswordPhoneNumber = (opts: RequiredPhoneNumberOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/phone-number/reset-password\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: resetPasswordPhoneNumberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Reset password using phone number OTP\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Password reset successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Indicates if the password was reset successfully\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [true],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"status\"],\n\t\t\t\t\t\t\t\t\t},\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},\n\t\tasync (ctx) => {\n\t\t\tconst verification =\n\t\t\t\tawait ctx.context.internalAdapter.findVerificationValue(\n\t\t\t\t\t`${ctx.body.phoneNumber}-request-password-reset`,\n\t\t\t\t);\n\t\t\tif (!verification) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.OTP_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (verification.expiresAt < new Date()) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.OTP_EXPIRED,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst [otpValue, attempts] = verification.value.split(\":\");\n\t\t\tconst allowedAttempts = opts?.allowedAttempts || 3;\n\t\t\tif (attempts && parseInt(attempts) >= allowedAttempts) {\n\t\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(\n\t\t\t\t\tverification.id,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.TOO_MANY_ATTEMPTS,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (ctx.body.otp !== otpValue) {\n\t\t\t\tawait ctx.context.internalAdapter.updateVerificationValue(\n\t\t\t\t\tverification.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: `${otpValue}:${parseInt(attempts || \"0\") + 1}`,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_OTP,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst user = await ctx.context.adapter.findOne<User>({\n\t\t\t\tmodel: \"user\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"phoneNumber\",\n\t\t\t\t\t\tvalue: ctx.body.phoneNumber,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.UNEXPECTED_ERROR,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst minLength = ctx.context.password.config.minPasswordLength;\n\t\t\tconst maxLength = ctx.context.password.config.maxPasswordLength;\n\t\t\tif (ctx.body.newPassword.length < minLength) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: BASE_ERROR_CODES.PASSWORD_TOO_SHORT,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (ctx.body.newPassword.length > maxLength) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: BASE_ERROR_CODES.PASSWORD_TOO_LONG,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst hashedPassword = await ctx.context.password.hash(\n\t\t\t\tctx.body.newPassword,\n\t\t\t);\n\t\t\tawait ctx.context.internalAdapter.updatePassword(user.id, hashedPassword);\n\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(\n\t\t\t\tverification.id,\n\t\t\t);\n\n\t\t\tif (ctx.context.options.emailAndPassword?.revokeSessionsOnPasswordReset) {\n\t\t\t\tawait ctx.context.internalAdapter.deleteSessions(user.id);\n\t\t\t}\n\n\t\t\treturn ctx.json({\n\t\t\t\tstatus: true,\n\t\t\t});\n\t\t},\n\t);\n\nfunction generateOTP(size: number) {\n\treturn generateRandomString(size, \"0-9\");\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,MAAM,8BAA8B,EAAE,OAAO;CAC5C,aAAa,EAAE,QAAQ,CAAC,KAAK,EAC5B,aAAa,gDACb,CAAC;CACF,UAAU,EAAE,QAAQ,CAAC,KAAK,EACzB,aAAa,gCACb,CAAC;CACF,YAAY,EACV,SAAS,CACT,KAAK,EACL,aAAa,kCACb,CAAC,CACD,UAAU;CACZ,CAAC;;;;;;;;;;;;;;;;AAiBF,MAAa,qBAAqB,SACjC,mBACC,yBACA;CACC,QAAQ;CACR,MAAM;CACN,UAAU,EACT,SAAS;EACR,SAAS;EACT,aAAa;EACb,WAAW;GACV,KAAK;IACJ,aAAa;IACb,SAAS,EACR,oBAAoB,EACnB,QAAQ;KACP,MAAM;KACN,YAAY;MACX,MAAM,EACL,MAAM,6BACN;MACD,SAAS,EACR,MAAM,gCACN;MACD;KACD,EACD,EACD;IACD;GACD,KAAK,EACJ,aAAa,oCACb;GACD;EACD,EACD;CACD,EACD,OAAO,QAAQ;CACd,MAAM,EAAE,UAAU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B,eAAe,KAAK,IAAI,eAAe;AACzE,OAAM,IAAI,QAAQ,gBAAgB,wBACjC,aAAa,GACb;AAED,KAAI,IAAI,QAAQ,QAAQ,kBAAkB,8BACzC,OAAM,IAAI,QAAQ,gBAAgB,eAAe,KAAK,GAAG;AAG1D,QAAO,IAAI,KAAK,EACf,QAAQ,MACR,CAAC;EAEH;AAEF,SAAS,YAAY,MAAc;AAClC,QAAO,qBAAqB,MAAM,MAAM"}
|
|
1
|
+
{"version":3,"file":"routes.mjs","names":["user"],"sources":["../../../src/plugins/phone-number/routes.ts"],"sourcesContent":["import { createAuthEndpoint } from \"@better-auth/core/api\";\nimport { BASE_ERROR_CODES } from \"@better-auth/core/error\";\nimport { APIError } from \"better-call\";\nimport * as z from \"zod\";\nimport { getSessionFromCtx } from \"../../api\";\nimport { setSessionCookie } from \"../../cookies\";\nimport { generateRandomString } from \"../../crypto/random\";\nimport { parseUserInput } from \"../../db\";\nimport { parseUserOutput } from \"../../db/schema\";\nimport type { User } from \"../../types\";\nimport { getDate } from \"../../utils/date\";\nimport { PHONE_NUMBER_ERROR_CODES } from \"./error-codes\";\nimport type { PhoneNumberOptions, UserWithPhoneNumber } from \"./types\";\n\nexport type RequiredPhoneNumberOptions = PhoneNumberOptions & {\n\texpiresIn: number;\n\totpLength: number;\n\tphoneNumber: string;\n\tphoneNumberVerified: string;\n\tcode: string;\n\tcreatedAt: string;\n};\n\nconst signInPhoneNumberBodySchema = z.object({\n\tphoneNumber: z.string().meta({\n\t\tdescription: 'Phone number to sign in. Eg: \"+1234567890\"',\n\t}),\n\tpassword: z.string().meta({\n\t\tdescription: \"Password to use for sign in.\",\n\t}),\n\trememberMe: z\n\t\t.boolean()\n\t\t.meta({\n\t\t\tdescription: \"Remember the session. Eg: true\",\n\t\t})\n\t\t.optional(),\n});\n\n/**\n * ### Endpoint\n *\n * POST `/sign-in/phone-number`\n *\n * ### API Methods\n *\n * **server:**\n * `auth.api.signInPhoneNumber`\n *\n * **client:**\n * `authClient.signIn.phoneNumber`\n *\n * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/phone-number#api-method-sign-in-phone-number)\n */\nexport const signInPhoneNumber = (opts: RequiredPhoneNumberOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/sign-in/phone-number\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: signInPhoneNumberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tsummary: \"Sign in with phone number\",\n\t\t\t\t\tdescription: \"Use this endpoint to sign in with phone number\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t200: {\n\t\t\t\t\t\t\tdescription: \"Success\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tuser: {\n\t\t\t\t\t\t\t\t\t\t\t\t$ref: \"#/components/schemas/User\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tsession: {\n\t\t\t\t\t\t\t\t\t\t\t\t$ref: \"#/components/schemas/Session\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\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\t400: {\n\t\t\t\t\t\t\tdescription: \"Invalid phone number or password\",\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},\n\t\tasync (ctx) => {\n\t\t\tconst { password, phoneNumber } = ctx.body;\n\n\t\t\tif (opts.phoneNumberValidator) {\n\t\t\t\tconst isValidNumber = await opts.phoneNumberValidator(\n\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t);\n\t\t\t\tif (!isValidNumber) {\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst user = await ctx.context.adapter.findOne<UserWithPhoneNumber>({\n\t\t\t\tmodel: \"user\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"phoneNumber\",\n\t\t\t\t\t\tvalue: phoneNumber,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) {\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER_OR_PASSWORD,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (opts.requireVerification) {\n\t\t\t\tif (!user.phoneNumberVerified) {\n\t\t\t\t\tconst otp = generateOTP(opts.otpLength);\n\t\t\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\t\t\tvalue: otp,\n\t\t\t\t\t\tidentifier: phoneNumber,\n\t\t\t\t\t\texpiresAt: getDate(opts.expiresIn, \"sec\"),\n\t\t\t\t\t});\n\t\t\t\t\tif (opts.sendOTP) {\n\t\t\t\t\t\tawait ctx.context.runInBackgroundOrAwait(\n\t\t\t\t\t\t\topts.sendOTP(\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tphoneNumber,\n\t\t\t\t\t\t\t\t\tcode: otp,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tctx,\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\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.PHONE_NUMBER_NOT_VERIFIED,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst accounts = await ctx.context.internalAdapter.findAccountByUserId(\n\t\t\t\tuser.id,\n\t\t\t);\n\t\t\tconst credentialAccount = accounts.find(\n\t\t\t\t(a) => a.providerId === \"credential\",\n\t\t\t);\n\t\t\tif (!credentialAccount) {\n\t\t\t\tctx.context.logger.error(\"Credential account not found\", {\n\t\t\t\t\tphoneNumber,\n\t\t\t\t});\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER_OR_PASSWORD,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst currentPassword = credentialAccount?.password;\n\t\t\tif (!currentPassword) {\n\t\t\t\tctx.context.logger.error(\"Password not found\", { phoneNumber });\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.UNEXPECTED_ERROR,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst validPassword = await ctx.context.password.verify({\n\t\t\t\thash: currentPassword,\n\t\t\t\tpassword,\n\t\t\t});\n\t\t\tif (!validPassword) {\n\t\t\t\tctx.context.logger.error(\"Invalid password\");\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER_OR_PASSWORD,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\t\tuser.id,\n\t\t\t\tctx.body.rememberMe === false,\n\t\t\t);\n\t\t\tif (!session) {\n\t\t\t\tctx.context.logger.error(\"Failed to create session\");\n\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\tmessage: BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait setSessionCookie(\n\t\t\t\tctx,\n\t\t\t\t{\n\t\t\t\t\tsession,\n\t\t\t\t\tuser: user,\n\t\t\t\t},\n\t\t\t\tctx.body.rememberMe === false,\n\t\t\t);\n\t\t\treturn ctx.json({\n\t\t\t\ttoken: session.token,\n\t\t\t\tuser: parseUserOutput(ctx.context.options, user),\n\t\t\t});\n\t\t},\n\t);\n\nconst sendPhoneNumberOTPBodySchema = z.object({\n\tphoneNumber: z.string().meta({\n\t\tdescription: 'Phone number to send OTP. Eg: \"+1234567890\"',\n\t}),\n});\n\n/**\n * ### Endpoint\n *\n * POST `/phone-number/send-otp`\n *\n * ### API Methods\n *\n * **server:**\n * `auth.api.sendPhoneNumberOTP`\n *\n * **client:**\n * `authClient.phoneNumber.sendOtp`\n *\n * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/phone-number#api-method-phone-number-send-otp)\n */\nexport const sendPhoneNumberOTP = (opts: RequiredPhoneNumberOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/phone-number/send-otp\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: sendPhoneNumberOTPBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tsummary: \"Send OTP to phone number\",\n\t\t\t\t\tdescription: \"Use this endpoint to send OTP to phone number\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t200: {\n\t\t\t\t\t\t\tdescription: \"Success\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\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},\n\t\tasync (ctx) => {\n\t\t\tif (!opts?.sendOTP) {\n\t\t\t\tctx.context.logger.warn(\"sendOTP not implemented\");\n\t\t\t\tthrow new APIError(\"NOT_IMPLEMENTED\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.SEND_OTP_NOT_IMPLEMENTED,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (opts.phoneNumberValidator) {\n\t\t\t\tconst isValidNumber = await opts.phoneNumberValidator(\n\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t);\n\t\t\t\tif (!isValidNumber) {\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst code = generateOTP(opts.otpLength);\n\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\tvalue: `${code}:0`,\n\t\t\t\tidentifier: ctx.body.phoneNumber,\n\t\t\t\texpiresAt: getDate(opts.expiresIn, \"sec\"),\n\t\t\t});\n\t\t\tawait ctx.context.runInBackgroundOrAwait(\n\t\t\t\topts.sendOTP(\n\t\t\t\t\t{\n\t\t\t\t\t\tphoneNumber: ctx.body.phoneNumber,\n\t\t\t\t\t\tcode,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn ctx.json({ message: \"code sent\" });\n\t\t},\n\t);\n\nconst verifyPhoneNumberBodySchema = z\n\t.object({\n\t\t/**\n\t\t * Phone number\n\t\t */\n\t\tphoneNumber: z.string().meta({\n\t\t\tdescription: 'Phone number to verify. Eg: \"+1234567890\"',\n\t\t}),\n\t\t/**\n\t\t * OTP code\n\t\t */\n\t\tcode: z.string().meta({\n\t\t\tdescription: 'OTP code. Eg: \"123456\"',\n\t\t}),\n\t\t/**\n\t\t * Disable session creation after verification\n\t\t * @default false\n\t\t */\n\t\tdisableSession: z\n\t\t\t.boolean()\n\t\t\t.meta({\n\t\t\t\tdescription: \"Disable session creation after verification. Eg: false\",\n\t\t\t})\n\t\t\t.optional(),\n\t\t/**\n\t\t * This checks if there is a session already\n\t\t * and updates the phone number with the provided\n\t\t * phone number\n\t\t */\n\t\tupdatePhoneNumber: z\n\t\t\t.boolean()\n\t\t\t.meta({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Check if there is a session and update the phone number. Eg: true\",\n\t\t\t})\n\t\t\t.optional(),\n\t})\n\t.and(z.record(z.string(), z.any()));\n\n/**\n * ### Endpoint\n *\n * POST `/phone-number/verify`\n *\n * ### API Methods\n *\n * **server:**\n * `auth.api.verifyPhoneNumber`\n *\n * **client:**\n * `authClient.phoneNumber.verify`\n *\n * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/phone-number#api-method-phone-number-verify)\n */\nexport const verifyPhoneNumber = (opts: RequiredPhoneNumberOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/phone-number/verify\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: verifyPhoneNumberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tsummary: \"Verify phone number\",\n\t\t\t\t\tdescription: \"Use this endpoint to verify phone number\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Phone number verified successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Indicates if the verification was successful\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [true],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\ttoken: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Session token if session is created, null if disableSession is true or no session is created\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tuser: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the user\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\temail: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"email\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"User's email address\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\temailVerified: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Whether the email is verified\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tname: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"User's name\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\timage: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"uri\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"User's profile image URL\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tphoneNumber: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"User's phone number\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tphoneNumberVerified: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Whether the phone number is verified\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the user was created\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\tupdatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"Timestamp when the user was last updated\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\trequired: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"phoneNumber\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"phoneNumberVerified\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"createdAt\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"updatedAt\",\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"User object with phone number details, null if no user is created or found\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"status\"],\n\t\t\t\t\t\t\t\t\t},\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\t400: {\n\t\t\t\t\t\t\tdescription: \"Invalid OTP\",\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},\n\t\tasync (ctx) => {\n\t\t\tif (opts?.verifyOTP) {\n\t\t\t\t// Use custom verifyOTP if provided\n\t\t\t\tconst isValid = await opts.verifyOTP(\n\t\t\t\t\t{\n\t\t\t\t\t\tphoneNumber: ctx.body.phoneNumber,\n\t\t\t\t\t\tcode: ctx.body.code,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t);\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_OTP,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Clean up verification value\n\t\t\t\tconst otp = await ctx.context.internalAdapter.findVerificationValue(\n\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t);\n\t\t\t\tif (otp) {\n\t\t\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(otp.id);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Default internal verification logic\n\t\t\t\tconst otp = await ctx.context.internalAdapter.findVerificationValue(\n\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t);\n\n\t\t\t\tif (!otp || otp.expiresAt < new Date()) {\n\t\t\t\t\tif (otp && otp.expiresAt < new Date()) {\n\t\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.OTP_EXPIRED,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.OTP_NOT_FOUND,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst [otpValue, attempts] = otp.value.split(\":\");\n\t\t\t\tconst allowedAttempts = opts?.allowedAttempts || 3;\n\t\t\t\tif (attempts && parseInt(attempts) >= allowedAttempts) {\n\t\t\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(otp.id);\n\t\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.TOO_MANY_ATTEMPTS,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (otpValue !== ctx.body.code) {\n\t\t\t\t\tawait ctx.context.internalAdapter.updateVerificationValue(otp.id, {\n\t\t\t\t\t\tvalue: `${otpValue}:${parseInt(attempts || \"0\") + 1}`,\n\t\t\t\t\t});\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_OTP,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(otp.id);\n\t\t\t}\n\n\t\t\tif (ctx.body.updatePhoneNumber) {\n\t\t\t\tconst session = await getSessionFromCtx(ctx);\n\t\t\t\tif (!session) {\n\t\t\t\t\tthrow new APIError(\"UNAUTHORIZED\", {\n\t\t\t\t\t\tmessage: BASE_ERROR_CODES.USER_NOT_FOUND,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst existingUser =\n\t\t\t\t\tawait ctx.context.adapter.findMany<UserWithPhoneNumber>({\n\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\twhere: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tfield: \"phoneNumber\",\n\t\t\t\t\t\t\t\tvalue: ctx.body.phoneNumber,\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\tif (existingUser.length) {\n\t\t\t\t\tthrow ctx.error(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.PHONE_NUMBER_EXIST,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst user =\n\t\t\t\t\tawait ctx.context.internalAdapter.updateUser<UserWithPhoneNumber>(\n\t\t\t\t\t\tsession.user.id,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[opts.phoneNumber]: ctx.body.phoneNumber,\n\t\t\t\t\t\t\t[opts.phoneNumberVerified]: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\treturn ctx.json({\n\t\t\t\t\tstatus: true,\n\t\t\t\t\ttoken: session.session.token,\n\t\t\t\t\tuser: parseUserOutput(ctx.context.options, user),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet user = await ctx.context.adapter.findOne<UserWithPhoneNumber>({\n\t\t\t\tmodel: \"user\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: ctx.body.phoneNumber,\n\t\t\t\t\t\tfield: opts.phoneNumber,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) {\n\t\t\t\tif (opts?.signUpOnVerification) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tphoneNumber: _,\n\t\t\t\t\t\tcode: __,\n\t\t\t\t\t\tdisableSession: ___,\n\t\t\t\t\t\tupdatePhoneNumber: ____,\n\t\t\t\t\t\t...rest\n\t\t\t\t\t} = ctx.body;\n\t\t\t\t\tconst additionalFields = parseUserInput(\n\t\t\t\t\t\tctx.context.options,\n\t\t\t\t\t\trest,\n\t\t\t\t\t\t\"create\",\n\t\t\t\t\t);\n\t\t\t\t\tuser =\n\t\t\t\t\t\tawait ctx.context.internalAdapter.createUser<UserWithPhoneNumber>({\n\t\t\t\t\t\t\t...additionalFields,\n\t\t\t\t\t\t\temail: opts.signUpOnVerification.getTempEmail(\n\t\t\t\t\t\t\t\tctx.body.phoneNumber,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tname: opts.signUpOnVerification.getTempName\n\t\t\t\t\t\t\t\t? opts.signUpOnVerification.getTempName(ctx.body.phoneNumber)\n\t\t\t\t\t\t\t\t: ctx.body.phoneNumber,\n\t\t\t\t\t\t\t[opts.phoneNumber]: ctx.body.phoneNumber,\n\t\t\t\t\t\t\t[opts.phoneNumberVerified]: true,\n\t\t\t\t\t\t});\n\t\t\t\t\tif (!user) {\n\t\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\t\tmessage: BASE_ERROR_CODES.FAILED_TO_CREATE_USER,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tuser =\n\t\t\t\t\tawait ctx.context.internalAdapter.updateUser<UserWithPhoneNumber>(\n\t\t\t\t\t\tuser.id,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[opts.phoneNumberVerified]: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t}\n\t\t\tif (!user) {\n\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\tmessage: BASE_ERROR_CODES.FAILED_TO_UPDATE_USER,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait opts?.callbackOnVerification?.(\n\t\t\t\t{\n\t\t\t\t\tphoneNumber: ctx.body.phoneNumber,\n\t\t\t\t\tuser,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tif (!ctx.body.disableSession) {\n\t\t\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\t\t\tuser.id,\n\t\t\t\t);\n\t\t\t\tif (!session) {\n\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\tmessage: BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tawait setSessionCookie(ctx, {\n\t\t\t\t\tsession,\n\t\t\t\t\tuser,\n\t\t\t\t});\n\t\t\t\treturn ctx.json({\n\t\t\t\t\tstatus: true,\n\t\t\t\t\ttoken: session.token,\n\t\t\t\t\tuser: parseUserOutput(ctx.context.options, user),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json({\n\t\t\t\tstatus: true,\n\t\t\t\ttoken: null,\n\t\t\t\tuser: parseUserOutput(ctx.context.options, user),\n\t\t\t});\n\t\t},\n\t);\n\nconst requestPasswordResetPhoneNumberBodySchema = z.object({\n\tphoneNumber: z.string(),\n});\n\nexport const requestPasswordResetPhoneNumber = (\n\topts: RequiredPhoneNumberOptions,\n) =>\n\tcreateAuthEndpoint(\n\t\t\"/phone-number/request-password-reset\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: requestPasswordResetPhoneNumberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Request OTP for password reset via phone number\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"OTP sent successfully for password reset\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Indicates if the OTP was sent successfully\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [true],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"status\"],\n\t\t\t\t\t\t\t\t\t},\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},\n\t\tasync (ctx) => {\n\t\t\tconst user = await ctx.context.adapter.findOne<UserWithPhoneNumber>({\n\t\t\t\tmodel: \"user\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: ctx.body.phoneNumber,\n\t\t\t\t\t\tfield: opts.phoneNumber,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tconst code = generateOTP(opts.otpLength);\n\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\tvalue: `${code}:0`,\n\t\t\t\tidentifier: `${ctx.body.phoneNumber}-request-password-reset`,\n\t\t\t\texpiresAt: getDate(opts.expiresIn, \"sec\"),\n\t\t\t});\n\t\t\t// to avoid leaking the existence of the phone number\n\t\t\tif (!user) {\n\t\t\t\treturn ctx.json({\n\t\t\t\t\tstatus: true,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (opts.sendPasswordResetOTP) {\n\t\t\t\tawait ctx.context.runInBackgroundOrAwait(\n\t\t\t\t\topts.sendPasswordResetOTP(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tphoneNumber: ctx.body.phoneNumber,\n\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tctx,\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});\n\t\t},\n\t);\n\nconst resetPasswordPhoneNumberBodySchema = z.object({\n\totp: z.string().meta({\n\t\tdescription: 'The one time password to reset the password. Eg: \"123456\"',\n\t}),\n\tphoneNumber: z.string().meta({\n\t\tdescription:\n\t\t\t'The phone number to the account which intends to reset the password for. Eg: \"+1234567890\"',\n\t}),\n\tnewPassword: z.string().meta({\n\t\tdescription: `The new password. Eg: \"new-and-secure-password\"`,\n\t}),\n});\n\nexport const resetPasswordPhoneNumber = (opts: RequiredPhoneNumberOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/phone-number/reset-password\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: resetPasswordPhoneNumberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Reset password using phone number OTP\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Password reset successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Indicates if the password was reset successfully\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [true],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"status\"],\n\t\t\t\t\t\t\t\t\t},\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},\n\t\tasync (ctx) => {\n\t\t\tconst verification =\n\t\t\t\tawait ctx.context.internalAdapter.findVerificationValue(\n\t\t\t\t\t`${ctx.body.phoneNumber}-request-password-reset`,\n\t\t\t\t);\n\t\t\tif (!verification) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.OTP_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (verification.expiresAt < new Date()) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.OTP_EXPIRED,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst [otpValue, attempts] = verification.value.split(\":\");\n\t\t\tconst allowedAttempts = opts?.allowedAttempts || 3;\n\t\t\tif (attempts && parseInt(attempts) >= allowedAttempts) {\n\t\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(\n\t\t\t\t\tverification.id,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.TOO_MANY_ATTEMPTS,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (ctx.body.otp !== otpValue) {\n\t\t\t\tawait ctx.context.internalAdapter.updateVerificationValue(\n\t\t\t\t\tverification.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: `${otpValue}:${parseInt(attempts || \"0\") + 1}`,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.INVALID_OTP,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst user = await ctx.context.adapter.findOne<User>({\n\t\t\t\tmodel: \"user\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"phoneNumber\",\n\t\t\t\t\t\tvalue: ctx.body.phoneNumber,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!user) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: PHONE_NUMBER_ERROR_CODES.UNEXPECTED_ERROR,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst minLength = ctx.context.password.config.minPasswordLength;\n\t\t\tconst maxLength = ctx.context.password.config.maxPasswordLength;\n\t\t\tif (ctx.body.newPassword.length < minLength) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: BASE_ERROR_CODES.PASSWORD_TOO_SHORT,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (ctx.body.newPassword.length > maxLength) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: BASE_ERROR_CODES.PASSWORD_TOO_LONG,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst hashedPassword = await ctx.context.password.hash(\n\t\t\t\tctx.body.newPassword,\n\t\t\t);\n\t\t\tawait ctx.context.internalAdapter.updatePassword(user.id, hashedPassword);\n\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(\n\t\t\t\tverification.id,\n\t\t\t);\n\n\t\t\tif (ctx.context.options.emailAndPassword?.revokeSessionsOnPasswordReset) {\n\t\t\t\tawait ctx.context.internalAdapter.deleteSessions(user.id);\n\t\t\t}\n\n\t\t\treturn ctx.json({\n\t\t\t\tstatus: true,\n\t\t\t});\n\t\t},\n\t);\n\nfunction generateOTP(size: number) {\n\treturn generateRandomString(size, \"0-9\");\n}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAM,8BAA8B,EAAE,OAAO;CAC5C,aAAa,EAAE,QAAQ,CAAC,KAAK,EAC5B,aAAa,gDACb,CAAC;CACF,UAAU,EAAE,QAAQ,CAAC,KAAK,EACzB,aAAa,gCACb,CAAC;CACF,YAAY,EACV,SAAS,CACT,KAAK,EACL,aAAa,kCACb,CAAC,CACD,UAA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,CAAC;;CAEH,MAAM,OAAO,MAAM,IAAI,QAAQ,QAAQ,QAAc;EACpD,OAAO;EACP,OAAO,CACN;GACC,OAAO;GACP,OAAO,IAAI,KAAK;GAChB,CACD;EACD,CAAC;AACF,KAAI,CAAC,KACJ,OAAM,IAAI,SAAS,eAAe,EACjC,SAAS,yBAAyB,kBAClC,CAAC;CAEH,MAAM,YAAY,IAAI,QAAQ,SAAS,OAAO;CAC9C,MAAM,YAAY,IAAI,QAAQ,SAAS,OAAO;AAC9C,KAAI,IAAI,KAAK,YAAY,SAAS,UACjC,OAAM,IAAI,SAAS,eAAe,EACjC,SAAS,iBAAiB,oBAC1B,CAAC;AAEH,KAAI,IAAI,KAAK,YAAY,SAAS,UACjC,OAAM,IAAI,SAAS,eAAe,EACjC,SAAS,iBAAiB,mBAC1B,CAAC;CAEH,MAAM,iBAAiB,MAAM,IAAI,QAAQ,SAAS,KACjD,IAAI,KAAK,YACT;AACD,OAAM,IAAI,QAAQ,gBAAgB,eAAe,KAAK,IAAI,eAAe;AACzE,OAAM,IAAI,QAAQ,gBAAgB,wBACjC,aAAa,GACb;AAED,KAAI,IAAI,QAAQ,QAAQ,kBAAkB,8BACzC,OAAM,IAAI,QAAQ,gBAAgB,eAAe,KAAK,GAAG;AAG1D,QAAO,IAAI,KAAK,EACf,QAAQ,MACR,CAAC;EAEH;AAEF,SAAS,YAAY,MAAc;AAClC,QAAO,qBAAqB,MAAM,MAAM"}
|
|
@@ -2,7 +2,7 @@ import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
|
2
2
|
import "../../types/index.mjs";
|
|
3
3
|
import { schema } from "./schema.mjs";
|
|
4
4
|
import { ENSLookupArgs, ENSLookupResult, SIWEVerifyMessageArgs } from "./types.mjs";
|
|
5
|
-
import * as
|
|
5
|
+
import * as better_call258 from "better-call";
|
|
6
6
|
import * as z from "zod";
|
|
7
7
|
|
|
8
8
|
//#region src/plugins/siwe/index.d.ts
|
|
@@ -49,7 +49,7 @@ declare const siwe: (options: SIWEPluginOptions) => {
|
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
endpoints: {
|
|
52
|
-
getSiweNonce:
|
|
52
|
+
getSiweNonce: better_call258.StrictEndpoint<"/siwe/nonce", {
|
|
53
53
|
method: "POST";
|
|
54
54
|
body: z.ZodObject<{
|
|
55
55
|
walletAddress: z.ZodString;
|
|
@@ -58,7 +58,7 @@ declare const siwe: (options: SIWEPluginOptions) => {
|
|
|
58
58
|
}, {
|
|
59
59
|
nonce: string;
|
|
60
60
|
}>;
|
|
61
|
-
verifySiweMessage:
|
|
61
|
+
verifySiweMessage: better_call258.StrictEndpoint<"/siwe/verify", {
|
|
62
62
|
method: "POST";
|
|
63
63
|
body: z.ZodObject<{
|
|
64
64
|
message: z.ZodString;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserWithTwoFactor } from "../types.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as better_call754 from "better-call";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/two-factor/backup-codes/index.d.ts
|
|
@@ -61,7 +61,7 @@ declare const backupCode2fa: (opts: BackupCodeOptions) => {
|
|
|
61
61
|
*
|
|
62
62
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-verify-backup-code)
|
|
63
63
|
*/
|
|
64
|
-
verifyBackupCode:
|
|
64
|
+
verifyBackupCode: better_call754.StrictEndpoint<"/two-factor/verify-backup-code", {
|
|
65
65
|
method: "POST";
|
|
66
66
|
body: z.ZodObject<{
|
|
67
67
|
code: z.ZodString;
|
|
@@ -187,12 +187,12 @@ declare const backupCode2fa: (opts: BackupCodeOptions) => {
|
|
|
187
187
|
*
|
|
188
188
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-generate-backup-codes)
|
|
189
189
|
*/
|
|
190
|
-
generateBackupCodes:
|
|
190
|
+
generateBackupCodes: better_call754.StrictEndpoint<"/two-factor/generate-backup-codes", {
|
|
191
191
|
method: "POST";
|
|
192
192
|
body: z.ZodObject<{
|
|
193
193
|
password: z.ZodString;
|
|
194
194
|
}, z.core.$strip>;
|
|
195
|
-
use: ((inputContext:
|
|
195
|
+
use: ((inputContext: better_call754.MiddlewareInputContext<better_call754.MiddlewareOptions>) => Promise<{
|
|
196
196
|
session: {
|
|
197
197
|
session: Record<string, any> & {
|
|
198
198
|
id: string;
|
|
@@ -263,7 +263,7 @@ declare const backupCode2fa: (opts: BackupCodeOptions) => {
|
|
|
263
263
|
*
|
|
264
264
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-view-backup-codes)
|
|
265
265
|
*/
|
|
266
|
-
viewBackupCodes:
|
|
266
|
+
viewBackupCodes: better_call754.StrictEndpoint<string, {
|
|
267
267
|
method: "POST";
|
|
268
268
|
body: z.ZodObject<{
|
|
269
269
|
userId: z.ZodCoercedString<unknown>;
|
|
@@ -3,7 +3,7 @@ import { OTPOptions, otp2fa } from "./otp/index.mjs";
|
|
|
3
3
|
import { TOTPOptions, totp2fa } from "./totp/index.mjs";
|
|
4
4
|
import { TwoFactorOptions, TwoFactorProvider, TwoFactorTable, UserWithTwoFactor } from "./types.mjs";
|
|
5
5
|
import { twoFactor } from "./index.mjs";
|
|
6
|
-
import * as
|
|
6
|
+
import * as _better_fetch_fetch79 from "@better-fetch/fetch";
|
|
7
7
|
|
|
8
8
|
//#region src/plugins/two-factor/client.d.ts
|
|
9
9
|
declare const twoFactorClient: (options?: {
|
|
@@ -33,7 +33,7 @@ declare const twoFactorClient: (options?: {
|
|
|
33
33
|
id: string;
|
|
34
34
|
name: string;
|
|
35
35
|
hooks: {
|
|
36
|
-
onSuccess(context:
|
|
36
|
+
onSuccess(context: _better_fetch_fetch79.SuccessContext<any>): Promise<void>;
|
|
37
37
|
};
|
|
38
38
|
}[];
|
|
39
39
|
};
|
|
@@ -4,8 +4,8 @@ import { TOTPOptions, totp2fa } from "./totp/index.mjs";
|
|
|
4
4
|
import { TwoFactorOptions, TwoFactorProvider, TwoFactorTable, UserWithTwoFactor } from "./types.mjs";
|
|
5
5
|
import { TWO_FACTOR_ERROR_CODES } from "./error-code.mjs";
|
|
6
6
|
import { twoFactorClient } from "./client.mjs";
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
7
|
+
import * as _better_auth_core9 from "@better-auth/core";
|
|
8
|
+
import * as better_call192 from "better-call";
|
|
9
9
|
import * as z from "zod";
|
|
10
10
|
|
|
11
11
|
//#region src/plugins/two-factor/index.d.ts
|
|
@@ -27,13 +27,13 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
27
27
|
*
|
|
28
28
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-enable)
|
|
29
29
|
*/
|
|
30
|
-
enableTwoFactor:
|
|
30
|
+
enableTwoFactor: better_call192.StrictEndpoint<"/two-factor/enable", {
|
|
31
31
|
method: "POST";
|
|
32
32
|
body: z.ZodObject<{
|
|
33
33
|
password: z.ZodString;
|
|
34
34
|
issuer: z.ZodOptional<z.ZodString>;
|
|
35
35
|
}, z.core.$strip>;
|
|
36
|
-
use: ((inputContext:
|
|
36
|
+
use: ((inputContext: better_call192.MiddlewareInputContext<better_call192.MiddlewareOptions>) => Promise<{
|
|
37
37
|
session: {
|
|
38
38
|
session: Record<string, any> & {
|
|
39
39
|
id: string;
|
|
@@ -106,12 +106,12 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
106
106
|
*
|
|
107
107
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-disable)
|
|
108
108
|
*/
|
|
109
|
-
disableTwoFactor:
|
|
109
|
+
disableTwoFactor: better_call192.StrictEndpoint<"/two-factor/disable", {
|
|
110
110
|
method: "POST";
|
|
111
111
|
body: z.ZodObject<{
|
|
112
112
|
password: z.ZodString;
|
|
113
113
|
}, z.core.$strip>;
|
|
114
|
-
use: ((inputContext:
|
|
114
|
+
use: ((inputContext: better_call192.MiddlewareInputContext<better_call192.MiddlewareOptions>) => Promise<{
|
|
115
115
|
session: {
|
|
116
116
|
session: Record<string, any> & {
|
|
117
117
|
id: string;
|
|
@@ -160,7 +160,7 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
160
160
|
}, {
|
|
161
161
|
status: boolean;
|
|
162
162
|
}>;
|
|
163
|
-
verifyBackupCode:
|
|
163
|
+
verifyBackupCode: better_call192.StrictEndpoint<"/two-factor/verify-backup-code", {
|
|
164
164
|
method: "POST";
|
|
165
165
|
body: z.ZodObject<{
|
|
166
166
|
code: z.ZodString;
|
|
@@ -271,12 +271,12 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
271
271
|
image?: string | null | undefined;
|
|
272
272
|
}) | UserWithTwoFactor;
|
|
273
273
|
}>;
|
|
274
|
-
generateBackupCodes:
|
|
274
|
+
generateBackupCodes: better_call192.StrictEndpoint<"/two-factor/generate-backup-codes", {
|
|
275
275
|
method: "POST";
|
|
276
276
|
body: z.ZodObject<{
|
|
277
277
|
password: z.ZodString;
|
|
278
278
|
}, z.core.$strip>;
|
|
279
|
-
use: ((inputContext:
|
|
279
|
+
use: ((inputContext: better_call192.MiddlewareInputContext<better_call192.MiddlewareOptions>) => Promise<{
|
|
280
280
|
session: {
|
|
281
281
|
session: Record<string, any> & {
|
|
282
282
|
id: string;
|
|
@@ -335,7 +335,7 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
335
335
|
status: boolean;
|
|
336
336
|
backupCodes: string[];
|
|
337
337
|
}>;
|
|
338
|
-
viewBackupCodes:
|
|
338
|
+
viewBackupCodes: better_call192.StrictEndpoint<string, {
|
|
339
339
|
method: "POST";
|
|
340
340
|
body: z.ZodObject<{
|
|
341
341
|
userId: z.ZodCoercedString<unknown>;
|
|
@@ -344,7 +344,7 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
344
344
|
status: boolean;
|
|
345
345
|
backupCodes: string[];
|
|
346
346
|
}>;
|
|
347
|
-
sendTwoFactorOTP:
|
|
347
|
+
sendTwoFactorOTP: better_call192.StrictEndpoint<"/two-factor/send-otp", {
|
|
348
348
|
method: "POST";
|
|
349
349
|
body: z.ZodOptional<z.ZodObject<{
|
|
350
350
|
trustDevice: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -375,7 +375,7 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
375
375
|
}, {
|
|
376
376
|
status: boolean;
|
|
377
377
|
}>;
|
|
378
|
-
verifyTwoFactorOTP:
|
|
378
|
+
verifyTwoFactorOTP: better_call192.StrictEndpoint<"/two-factor/verify-otp", {
|
|
379
379
|
method: "POST";
|
|
380
380
|
body: z.ZodObject<{
|
|
381
381
|
code: z.ZodString;
|
|
@@ -464,7 +464,7 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
464
464
|
image?: string | null | undefined;
|
|
465
465
|
};
|
|
466
466
|
}>;
|
|
467
|
-
generateTOTP:
|
|
467
|
+
generateTOTP: better_call192.StrictEndpoint<string, {
|
|
468
468
|
method: "POST";
|
|
469
469
|
body: z.ZodObject<{
|
|
470
470
|
secret: z.ZodString;
|
|
@@ -495,9 +495,9 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
495
495
|
}, {
|
|
496
496
|
code: string;
|
|
497
497
|
}>;
|
|
498
|
-
getTOTPURI:
|
|
498
|
+
getTOTPURI: better_call192.StrictEndpoint<"/two-factor/get-totp-uri", {
|
|
499
499
|
method: "POST";
|
|
500
|
-
use: ((inputContext:
|
|
500
|
+
use: ((inputContext: better_call192.MiddlewareInputContext<better_call192.MiddlewareOptions>) => Promise<{
|
|
501
501
|
session: {
|
|
502
502
|
session: Record<string, any> & {
|
|
503
503
|
id: string;
|
|
@@ -549,7 +549,7 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
549
549
|
}, {
|
|
550
550
|
totpURI: string;
|
|
551
551
|
}>;
|
|
552
|
-
verifyTOTP:
|
|
552
|
+
verifyTOTP: better_call192.StrictEndpoint<"/two-factor/verify-totp", {
|
|
553
553
|
method: "POST";
|
|
554
554
|
body: z.ZodObject<{
|
|
555
555
|
code: z.ZodString;
|
|
@@ -597,8 +597,8 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
|
|
|
597
597
|
options: NoInfer<O>;
|
|
598
598
|
hooks: {
|
|
599
599
|
after: {
|
|
600
|
-
matcher(context:
|
|
601
|
-
handler: (inputContext:
|
|
600
|
+
matcher(context: _better_auth_core9.HookEndpointContext): boolean;
|
|
601
|
+
handler: (inputContext: better_call192.MiddlewareInputContext<better_call192.MiddlewareOptions>) => Promise<{
|
|
602
602
|
twoFactorRedirect: boolean;
|
|
603
603
|
} | undefined>;
|
|
604
604
|
}[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UserWithTwoFactor } from "../types.mjs";
|
|
2
2
|
import { Awaitable, GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as
|
|
3
|
+
import * as better_call752 from "better-call";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/plugins/two-factor/otp/index.d.ts
|
|
@@ -74,7 +74,7 @@ declare const otp2fa: (options?: OTPOptions | undefined) => {
|
|
|
74
74
|
*
|
|
75
75
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-send-otp)
|
|
76
76
|
*/
|
|
77
|
-
sendTwoFactorOTP:
|
|
77
|
+
sendTwoFactorOTP: better_call752.StrictEndpoint<"/two-factor/send-otp", {
|
|
78
78
|
method: "POST";
|
|
79
79
|
body: z.ZodOptional<z.ZodObject<{
|
|
80
80
|
trustDevice: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -120,7 +120,7 @@ declare const otp2fa: (options?: OTPOptions | undefined) => {
|
|
|
120
120
|
*
|
|
121
121
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-verify-otp)
|
|
122
122
|
*/
|
|
123
|
-
verifyTwoFactorOTP:
|
|
123
|
+
verifyTwoFactorOTP: better_call752.StrictEndpoint<"/two-factor/verify-otp", {
|
|
124
124
|
method: "POST";
|
|
125
125
|
body: z.ZodObject<{
|
|
126
126
|
code: z.ZodString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BackupCodeOptions } from "../backup-codes/index.mjs";
|
|
2
2
|
import { UserWithTwoFactor } from "../types.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as better_call747 from "better-call";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/plugins/two-factor/totp/index.d.ts
|
|
@@ -44,7 +44,7 @@ declare const totp2fa: (options?: TOTPOptions | undefined) => {
|
|
|
44
44
|
*
|
|
45
45
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#totp)
|
|
46
46
|
*/
|
|
47
|
-
generateTOTP:
|
|
47
|
+
generateTOTP: better_call747.StrictEndpoint<string, {
|
|
48
48
|
method: "POST";
|
|
49
49
|
body: z.ZodObject<{
|
|
50
50
|
secret: z.ZodString;
|
|
@@ -90,9 +90,9 @@ declare const totp2fa: (options?: TOTPOptions | undefined) => {
|
|
|
90
90
|
*
|
|
91
91
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#getting-totp-uri)
|
|
92
92
|
*/
|
|
93
|
-
getTOTPURI:
|
|
93
|
+
getTOTPURI: better_call747.StrictEndpoint<"/two-factor/get-totp-uri", {
|
|
94
94
|
method: "POST";
|
|
95
|
-
use: ((inputContext:
|
|
95
|
+
use: ((inputContext: better_call747.MiddlewareInputContext<better_call747.MiddlewareOptions>) => Promise<{
|
|
96
96
|
session: {
|
|
97
97
|
session: Record<string, any> & {
|
|
98
98
|
id: string;
|
|
@@ -159,7 +159,7 @@ declare const totp2fa: (options?: TOTPOptions | undefined) => {
|
|
|
159
159
|
*
|
|
160
160
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#verifying-totp)
|
|
161
161
|
*/
|
|
162
|
-
verifyTOTP:
|
|
162
|
+
verifyTOTP: better_call747.StrictEndpoint<"/two-factor/verify-totp", {
|
|
163
163
|
method: "POST";
|
|
164
164
|
body: z.ZodObject<{
|
|
165
165
|
code: z.ZodString;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
2
2
|
import { UsernameSchema } from "./schema.mjs";
|
|
3
3
|
import { USERNAME_ERROR_CODES } from "./error-codes.mjs";
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
4
|
+
import * as _better_auth_core14 from "@better-auth/core";
|
|
5
|
+
import * as _better_auth_core_db1 from "@better-auth/core/db";
|
|
6
|
+
import * as better_call248 from "better-call";
|
|
7
7
|
import * as z from "zod";
|
|
8
8
|
|
|
9
9
|
//#region src/plugins/username/index.d.ts
|
|
@@ -67,7 +67,7 @@ type UsernameOptions = {
|
|
|
67
67
|
};
|
|
68
68
|
declare const username: (options?: UsernameOptions | undefined) => {
|
|
69
69
|
id: "username";
|
|
70
|
-
init(ctx:
|
|
70
|
+
init(ctx: _better_auth_core14.AuthContext): {
|
|
71
71
|
options: {
|
|
72
72
|
databaseHooks: {
|
|
73
73
|
user: {
|
|
@@ -80,7 +80,7 @@ declare const username: (options?: UsernameOptions | undefined) => {
|
|
|
80
80
|
emailVerified: boolean;
|
|
81
81
|
name: string;
|
|
82
82
|
image?: string | null | undefined;
|
|
83
|
-
} & Record<string, unknown>, context:
|
|
83
|
+
} & Record<string, unknown>, context: _better_auth_core14.GenericEndpointContext | null): Promise<{
|
|
84
84
|
data: {
|
|
85
85
|
displayUsername?: string | undefined;
|
|
86
86
|
username?: string | undefined;
|
|
@@ -103,7 +103,7 @@ declare const username: (options?: UsernameOptions | undefined) => {
|
|
|
103
103
|
emailVerified: boolean;
|
|
104
104
|
name: string;
|
|
105
105
|
image?: string | null | undefined;
|
|
106
|
-
}> & Record<string, unknown>, context:
|
|
106
|
+
}> & Record<string, unknown>, context: _better_auth_core14.GenericEndpointContext | null): Promise<{
|
|
107
107
|
data: {
|
|
108
108
|
displayUsername?: string | undefined;
|
|
109
109
|
username?: string | undefined;
|
|
@@ -122,7 +122,7 @@ declare const username: (options?: UsernameOptions | undefined) => {
|
|
|
122
122
|
};
|
|
123
123
|
};
|
|
124
124
|
endpoints: {
|
|
125
|
-
signInUsername:
|
|
125
|
+
signInUsername: better_call248.StrictEndpoint<"/sign-in/username", {
|
|
126
126
|
method: "POST";
|
|
127
127
|
body: z.ZodObject<{
|
|
128
128
|
username: z.ZodString;
|
|
@@ -188,7 +188,7 @@ declare const username: (options?: UsernameOptions | undefined) => {
|
|
|
188
188
|
displayUsername: string;
|
|
189
189
|
};
|
|
190
190
|
} | null>;
|
|
191
|
-
isUsernameAvailable:
|
|
191
|
+
isUsernameAvailable: better_call248.StrictEndpoint<"/is-username-available", {
|
|
192
192
|
method: "POST";
|
|
193
193
|
body: z.ZodObject<{
|
|
194
194
|
username: z.ZodString;
|
|
@@ -207,14 +207,14 @@ declare const username: (options?: UsernameOptions | undefined) => {
|
|
|
207
207
|
unique: true;
|
|
208
208
|
returned: true;
|
|
209
209
|
transform: {
|
|
210
|
-
input(value:
|
|
210
|
+
input(value: _better_auth_core_db1.DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
211
211
|
};
|
|
212
212
|
};
|
|
213
213
|
displayUsername: {
|
|
214
214
|
type: "string";
|
|
215
215
|
required: false;
|
|
216
216
|
transform: {
|
|
217
|
-
input(value:
|
|
217
|
+
input(value: _better_auth_core_db1.DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
218
218
|
};
|
|
219
219
|
};
|
|
220
220
|
};
|
|
@@ -222,8 +222,8 @@ declare const username: (options?: UsernameOptions | undefined) => {
|
|
|
222
222
|
};
|
|
223
223
|
hooks: {
|
|
224
224
|
before: {
|
|
225
|
-
matcher(context:
|
|
226
|
-
handler: (inputContext:
|
|
225
|
+
matcher(context: _better_auth_core14.HookEndpointContext): boolean;
|
|
226
|
+
handler: (inputContext: better_call248.MiddlewareInputContext<better_call248.MiddlewareOptions>) => Promise<void>;
|
|
227
227
|
}[];
|
|
228
228
|
};
|
|
229
229
|
options: UsernameOptions | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _better_auth_core_db14 from "@better-auth/core/db";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/username/schema.d.ts
|
|
4
4
|
declare const getSchema: (normalizer: {
|
|
@@ -14,14 +14,14 @@ declare const getSchema: (normalizer: {
|
|
|
14
14
|
unique: true;
|
|
15
15
|
returned: true;
|
|
16
16
|
transform: {
|
|
17
|
-
input(value:
|
|
17
|
+
input(value: _better_auth_core_db14.DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
displayUsername: {
|
|
21
21
|
type: "string";
|
|
22
22
|
required: false;
|
|
23
23
|
transform: {
|
|
24
|
-
input(value:
|
|
24
|
+
input(value: _better_auth_core_db14.DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
};
|