Edit: /tmp/tsx-0/17887-5d9eb2c4c07f631122c7a19bc959c92c2eb6f515 (46488B)
{"code":"__filename=\"/opt/canhelp/node_modules/better-auth/dist/plugins/email-otp/routes.mjs\";(()=>{\nvar __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf;var __hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,\"name\",{value,configurable:true});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from===\"object\"||typeof from===\"function\"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,\"default\",{value:mod,enumerable:true}):target,mod));var __toCommonJS=mod=>__copyProps(__defProp({},\"__esModule\",{value:true}),mod);var routes_exports={};__export(routes_exports,{changeEmailEmailOTP:()=>changeEmailEmailOTP,checkVerificationOTP:()=>checkVerificationOTP,createVerificationOTP:()=>createVerificationOTP,forgetPasswordEmailOTP:()=>forgetPasswordEmailOTP,getVerificationOTP:()=>getVerificationOTP,requestEmailChangeEmailOTP:()=>requestEmailChangeEmailOTP,requestPasswordResetEmailOTP:()=>requestPasswordResetEmailOTP,resetPasswordEmailOTP:()=>resetPasswordEmailOTP,sendVerificationOTP:()=>sendVerificationOTP,signInEmailOTP:()=>signInEmailOTP,verifyEmailOTP:()=>verifyEmailOTP});module.exports=__toCommonJS(routes_exports);var import_date=require(\"../../utils/date.mjs\");var import_schema=require(\"../../db/schema.mjs\");var import_random=require(\"../../crypto/random.mjs\");var import_crypto=require(\"../../crypto/index.mjs\");var import_cookies=require(\"../../cookies/index.mjs\");var import_session=require(\"../../api/routes/session.mjs\");var import_api=require(\"../../api/index.mjs\");var import_error_codes=require(\"./error-codes.mjs\");var import_utils=require(\"./utils.mjs\");var import_otp_token=require(\"./otp-token.mjs\");var import_error=require(\"@better-auth/core/error\");var import_api2=require(\"@better-auth/core/api\");var import_deprecate=require(\"@better-auth/core/utils/deprecate\");var z=__toESM(require(\"zod\"));const types=[\"email-verification\",\"sign-in\",\"forget-password\",\"change-email\"];async function resolveOTP(ctx,opts,email,type){const identifier=(0,import_utils.toOTPIdentifier)(type,email);if(opts.resendStrategy===\"reuse\"){const reused=await(0,import_otp_token.tryReuseOTP)(ctx,opts,identifier);if(reused)return reused}const otp=opts.generateOTP({email,type},ctx)||defaultOTPGenerator(opts);const storedOTP=await(0,import_otp_token.storeOTP)(ctx,opts,otp);await ctx.context.internalAdapter.createVerificationValue({value:`${storedOTP}:0`,identifier,expiresAt:(0,import_date.getDate)(opts.expiresIn,\"sec\")}).catch(async()=>{await ctx.context.internalAdapter.deleteVerificationByIdentifier(identifier);await ctx.context.internalAdapter.createVerificationValue({value:`${storedOTP}:0`,identifier,expiresAt:(0,import_date.getDate)(opts.expiresIn,\"sec\")})});return otp}__name(resolveOTP,\"resolveOTP\");const sendVerificationOTPBodySchema=z.object({email:z.string({}).meta({description:\"Email address to send the OTP\"}),type:z.enum(types).meta({description:\"Type of the OTP\"})});const sendVerificationOTP=__name(opts=>(0,import_api2.createAuthEndpoint)(\"/email-otp/send-verification-otp\",{method:\"POST\",body:sendVerificationOTPBodySchema,metadata:{openapi:{operationId:\"sendEmailVerificationOTP\",description:\"Send a verification OTP to an email\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{success:{type:\"boolean\"}}}}}}}}}},async ctx=>{if(!opts?.sendVerificationOTP){ctx.context.logger.error(\"send email verification is not implemented\");throw import_api.APIError.fromStatus(\"BAD_REQUEST\",{message:\"send email verification is not implemented\"})}const email=ctx.body.email.toLowerCase();if(!z.email().safeParse(email).success)throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.INVALID_EMAIL);if(ctx.body.type===\"change-email\"){ctx.context.logger.error(\"Use the /email-otp/request-email-change endpoint to send OTP for changing email\");throw import_api.APIError.fromStatus(\"BAD_REQUEST\",{message:\"Invalid OTP type\"})}const identifier=(0,import_utils.toOTPIdentifier)(ctx.body.type,email);const otp=await resolveOTP(ctx,opts,email,ctx.body.type);const shouldSendOTP=ctx.body.type===\"sign-in\"&&!opts.disableSignUp;if(!await ctx.context.internalAdapter.findUserByEmail(email)&&!shouldSendOTP){await ctx.context.internalAdapter.deleteVerificationByIdentifier(identifier);return ctx.json({success:true})}await ctx.context.runInBackgroundOrAwait(opts.sendVerificationOTP({email,otp,type:ctx.body.type},ctx));return ctx.json({success:true})}),\"sendVerificationOTP\");const createVerificationOTPBodySchema=z.object({email:z.string({}).meta({description:\"Email address to send the OTP\"}),type:z.enum(types).meta({required:true,description:\"Type of the OTP\"})});const createVerificationOTP=__name(opts=>(0,import_api2.createAuthEndpoint)({method:\"POST\",body:createVerificationOTPBodySchema,metadata:{openapi:{operationId:\"createEmailVerificationOTP\",description:\"Create a verification OTP for an email\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"string\"}}}}}}}},async ctx=>{const email=ctx.body.email.toLowerCase();const otp=opts.generateOTP({email,type:ctx.body.type},ctx)||defaultOTPGenerator(opts);const storedOTP=await(0,import_otp_token.storeOTP)(ctx,opts,otp);await ctx.context.internalAdapter.createVerificationValue({value:`${storedOTP}:0`,identifier:(0,import_utils.toOTPIdentifier)(ctx.body.type,email),expiresAt:(0,import_date.getDate)(opts.expiresIn,\"sec\")});return otp}),\"createVerificationOTP\");const getVerificationOTPBodySchema=z.object({email:z.string({}).meta({description:\"Email address the OTP was sent to\"}),type:z.enum(types).meta({required:true,description:\"Type of the OTP\"})});const getVerificationOTP=__name(opts=>(0,import_api2.createAuthEndpoint)({method:\"GET\",query:getVerificationOTPBodySchema,metadata:{openapi:{operationId:\"getEmailVerificationOTP\",description:\"Get a verification OTP for an email\",responses:{\"200\":{description:\"OTP retrieved successfully or not found/expired\",content:{\"application/json\":{schema:{type:\"object\",properties:{otp:{type:\"string\",nullable:true,description:\"The stored OTP, or null if not found or expired\"}},required:[\"otp\"]}}}}}}}},async ctx=>{const email=ctx.query.email.toLowerCase();const verificationValue=await ctx.context.internalAdapter.findVerificationValue((0,import_utils.toOTPIdentifier)(ctx.query.type,email));if(!verificationValue||verificationValue.expiresAt
(0,import_api2.createAuthEndpoint)(\"/email-otp/check-verification-otp\",{method:\"POST\",body:checkVerificationOTPBodySchema,metadata:{openapi:{operationId:\"verifyEmailWithOTP\",description:\"Verify an email with an OTP\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{success:{type:\"boolean\"}}}}}}}}}},async ctx=>{const email=ctx.body.email.toLowerCase();if(!z.email().safeParse(email).success)throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.INVALID_EMAIL);if(!await ctx.context.internalAdapter.findUserByEmail(email))throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.USER_NOT_FOUND);const identifier=(0,import_utils.toOTPIdentifier)(ctx.body.type,email);const verificationValue=await ctx.context.internalAdapter.findVerificationValue(identifier);if(!verificationValue)throw import_api.APIError.from(\"BAD_REQUEST\",import_error_codes.EMAIL_OTP_ERROR_CODES.INVALID_OTP);if(verificationValue.expiresAt=allowedAttempts){await ctx.context.internalAdapter.deleteVerificationByIdentifier(identifier);throw import_api.APIError.from(\"FORBIDDEN\",import_error_codes.EMAIL_OTP_ERROR_CODES.TOO_MANY_ATTEMPTS)}if(!await(0,import_otp_token.verifyStoredOTP)(ctx,opts,otpValue,ctx.body.otp)){await ctx.context.internalAdapter.updateVerificationByIdentifier(identifier,{value:`${otpValue}:${parseInt(attempts||\"0\")+1}`});throw import_api.APIError.from(\"BAD_REQUEST\",import_error_codes.EMAIL_OTP_ERROR_CODES.INVALID_OTP)}return ctx.json({success:true})}),\"checkVerificationOTP\");const verifyEmailOTPBodySchema=z.object({email:z.string({}).meta({description:\"Email address to verify\"}),otp:z.string().meta({required:true,description:\"OTP to verify\"})});const verifyEmailOTP=__name(opts=>(0,import_api2.createAuthEndpoint)(\"/email-otp/verify-email\",{method:\"POST\",body:verifyEmailOTPBodySchema,metadata:{openapi:{description:\"Verify email with OTP\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{status:{type:\"boolean\",description:\"Indicates if the verification was successful\",enum:[true]},token:{type:\"string\",nullable:true,description:\"Session token if autoSignInAfterVerification is enabled, otherwise null\"},user:{$ref:\"#/components/schemas/User\"}},required:[\"status\",\"token\",\"user\"]}}}}}}}},async ctx=>{const email=ctx.body.email.toLowerCase();if(!z.email().safeParse(email).success)throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.INVALID_EMAIL);await atomicVerifyOTP(ctx,opts,(0,import_utils.toOTPIdentifier)(\"email-verification\",email),ctx.body.otp);const user=await ctx.context.internalAdapter.findUserByEmail(email);if(!user)throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.USER_NOT_FOUND);if(ctx.context.options.emailVerification?.beforeEmailVerification)await ctx.context.options.emailVerification.beforeEmailVerification(user.user,ctx.request);const updatedUser=await ctx.context.internalAdapter.updateUser(user.user.id,{email,emailVerified:true});await ctx.context.options.emailVerification?.afterEmailVerification?.(updatedUser,ctx.request);if(ctx.context.options.emailVerification?.autoSignInAfterVerification){const session=await ctx.context.internalAdapter.createSession(updatedUser.id);await(0,import_cookies.setSessionCookie)(ctx,{session,user:updatedUser});return ctx.json({status:true,token:session.token,user:(0,import_schema.parseUserOutput)(ctx.context.options,updatedUser)})}const currentSession=await(0,import_session.getSessionFromCtx)(ctx);if(currentSession&&updatedUser.emailVerified){const dontRememberMeCookie=await ctx.getSignedCookie(ctx.context.authCookies.dontRememberToken.name,ctx.context.secret);await(0,import_cookies.setCookieCache)(ctx,{session:currentSession.session,user:{...currentSession.user,emailVerified:true}},!!dontRememberMeCookie)}return ctx.json({status:true,token:null,user:(0,import_schema.parseUserOutput)(ctx.context.options,updatedUser)})}),\"verifyEmailOTP\");const signInEmailOTPBodySchema=z.object({email:z.string({}).meta({description:\"Email address to sign in\"}),otp:z.string().meta({required:true,description:\"OTP sent to the email\"}),name:z.string().meta({description:'User display name. Only used if the user is registering for the first time. Eg: \"my-name\"'}).optional(),image:z.string().meta({description:\"User profile image URL. Only used if the user is registering for the first time.\"}).optional()}).and(z.record(z.string(),z.any()));const signInEmailOTP=__name(opts=>(0,import_api2.createAuthEndpoint)(\"/sign-in/email-otp\",{method:\"POST\",body:signInEmailOTPBodySchema,metadata:{openapi:{operationId:\"signInWithEmailOTP\",description:\"Sign in with email and OTP\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{token:{type:\"string\",description:\"Session token for the authenticated session\"},user:{$ref:\"#/components/schemas/User\"}},required:[\"token\",\"user\"]}}}}}}}},async ctx=>{const{email:rawEmail,otp,name,image,...rest}=ctx.body;const email=rawEmail.toLowerCase();await atomicVerifyOTP(ctx,opts,(0,import_utils.toOTPIdentifier)(\"sign-in\",email),otp);const user=await ctx.context.internalAdapter.findUserByEmail(email);if(!user){if(opts.disableSignUp)throw import_api.APIError.from(\"BAD_REQUEST\",import_error_codes.EMAIL_OTP_ERROR_CODES.INVALID_OTP);const additionalFields=(0,import_schema.parseUserInput)(ctx.context.options,rest,\"create\");const newUser=await ctx.context.internalAdapter.createUser({...additionalFields,email,emailVerified:true,name:name||\"\",image});const session2=await ctx.context.internalAdapter.createSession(newUser.id);await(0,import_cookies.setSessionCookie)(ctx,{session:session2,user:newUser});return ctx.json({token:session2.token,user:(0,import_schema.parseUserOutput)(ctx.context.options,newUser)})}if(!user.user.emailVerified)await ctx.context.internalAdapter.updateUser(user.user.id,{emailVerified:true});const session=await ctx.context.internalAdapter.createSession(user.user.id);await(0,import_cookies.setSessionCookie)(ctx,{session,user:user.user});return ctx.json({token:session.token,user:(0,import_schema.parseUserOutput)(ctx.context.options,user.user)})}),\"signInEmailOTP\");const requestPasswordResetEmailOTPBodySchema=z.object({email:z.string().meta({description:\"Email address to send the OTP\"})});const requestPasswordResetEmailOTP=__name(opts=>(0,import_api2.createAuthEndpoint)(\"/email-otp/request-password-reset\",{method:\"POST\",body:requestPasswordResetEmailOTPBodySchema,metadata:{openapi:{operationId:\"requestPasswordResetWithEmailOTP\",description:\"Request password reset with email and OTP\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{success:{type:\"boolean\",description:\"Indicates if the OTP was sent successfully\"}}}}}}}}}},async ctx=>{const email=ctx.body.email;const identifier=(0,import_utils.toOTPIdentifier)(\"forget-password\",email);const otp=await resolveOTP(ctx,opts,email,\"forget-password\");if(!await ctx.context.internalAdapter.findUserByEmail(email)){await ctx.context.internalAdapter.deleteVerificationByIdentifier(identifier);return ctx.json({success:true})}await ctx.context.runInBackgroundOrAwait(opts.sendVerificationOTP({email,otp,type:\"forget-password\"},ctx));return ctx.json({success:true})}),\"requestPasswordResetEmailOTP\");const forgetPasswordEmailOTPBodySchema=z.object({email:z.string().meta({description:\"Email address to send the OTP\"})});const forgetPasswordEmailOTP=__name(opts=>{const warnDeprecation=(0,import_deprecate.deprecate)(()=>{},'The \"/forget-password/email-otp\" endpoint is deprecated. Please use \"/email-otp/request-password-reset\" instead. This endpoint will be removed in the next major version.');return(0,import_api2.createAuthEndpoint)(\"/forget-password/email-otp\",{method:\"POST\",body:forgetPasswordEmailOTPBodySchema,metadata:{openapi:{operationId:\"forgetPasswordWithEmailOTP\",description:\"Deprecated: Use /email-otp/request-password-reset instead.\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{success:{type:\"boolean\",description:\"Indicates if the OTP was sent successfully\"}}}}}}}}}},async ctx=>{warnDeprecation();const email=ctx.body.email;const identifier=(0,import_utils.toOTPIdentifier)(\"forget-password\",email);const otp=await resolveOTP(ctx,opts,email,\"forget-password\");if(!await ctx.context.internalAdapter.findUserByEmail(email)){await ctx.context.internalAdapter.deleteVerificationByIdentifier(identifier);return ctx.json({success:true})}await ctx.context.runInBackgroundOrAwait(opts.sendVerificationOTP({email,otp,type:\"forget-password\"},ctx));return ctx.json({success:true})})},\"forgetPasswordEmailOTP\");const resetPasswordEmailOTPBodySchema=z.object({email:z.string().meta({description:\"Email address to reset the password\"}),otp:z.string().meta({description:\"OTP sent to the email\"}),password:z.string().meta({description:\"New password\"})});const resetPasswordEmailOTP=__name(opts=>(0,import_api2.createAuthEndpoint)(\"/email-otp/reset-password\",{method:\"POST\",body:resetPasswordEmailOTPBodySchema,metadata:{openapi:{operationId:\"resetPasswordWithEmailOTP\",description:\"Reset password with email and OTP\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{success:{type:\"boolean\"}}}}}}}}}},async ctx=>{const email=ctx.body.email;await atomicVerifyOTP(ctx,opts,(0,import_utils.toOTPIdentifier)(\"forget-password\",email),ctx.body.otp);const user=await ctx.context.internalAdapter.findUserByEmail(email,{includeAccounts:true});if(!user)throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.USER_NOT_FOUND);const minPasswordLength=ctx.context.password.config.minPasswordLength;if(ctx.body.password.lengthmaxPasswordLength)throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.PASSWORD_TOO_LONG);const passwordHash=await ctx.context.password.hash(ctx.body.password);if(!user.accounts?.find(account=>account.providerId===\"credential\"))await ctx.context.internalAdapter.createAccount({userId:user.user.id,providerId:\"credential\",accountId:user.user.id,password:passwordHash});else await ctx.context.internalAdapter.updatePassword(user.user.id,passwordHash);if(ctx.context.options.emailAndPassword?.onPasswordReset)await ctx.context.options.emailAndPassword.onPasswordReset({user:user.user},ctx.request);if(!user.user.emailVerified)await ctx.context.internalAdapter.updateUser(user.user.id,{emailVerified:true});if(ctx.context.options.emailAndPassword?.revokeSessionsOnPasswordReset)await ctx.context.internalAdapter.deleteSessions(user.user.id);return ctx.json({success:true})}),\"resetPasswordEmailOTP\");const requestEmailChangeEmailOTPBodySchema=z.object({newEmail:z.string().meta({description:\"New email address to send the OTP\"}),otp:z.string().optional().meta({description:\"OTP sent to the current email. This is required if changeEmail.verifyCurrentEmail option is set to true\"})});const requestEmailChangeEmailOTP=__name(opts=>(0,import_api2.createAuthEndpoint)(\"/email-otp/request-email-change\",{method:\"POST\",body:requestEmailChangeEmailOTPBodySchema,use:[import_session.sensitiveSessionMiddleware],metadata:{openapi:{operationId:\"requestEmailChangeWithEmailOTP\",description:\"Request email change with verification OTP sent to the new email\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{success:{type:\"boolean\"}}}}}}}}}},async ctx=>{if(!opts.changeEmail?.enabled){ctx.context.logger.error(\"Change email with OTP is disabled.\");throw import_api.APIError.fromStatus(\"BAD_REQUEST\",{message:\"Change email with OTP is disabled\"})}const email=ctx.context.session.user.email.toLowerCase();const newEmail=ctx.body.newEmail.toLowerCase();if(!z.email().safeParse(newEmail).success)throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.INVALID_EMAIL);if(newEmail===email){ctx.context.logger.error(\"Email is the same\");throw import_api.APIError.fromStatus(\"BAD_REQUEST\",{message:\"Email is the same\"})}if(opts.changeEmail?.verifyCurrentEmail){if(!ctx.body.otp)throw import_api.APIError.fromStatus(\"BAD_REQUEST\",{message:\"OTP is required to verify current email\"});const currentEmailVerificationValue=await ctx.context.internalAdapter.findVerificationValue((0,import_utils.toOTPIdentifier)(\"email-verification\",email));if(!currentEmailVerificationValue)throw import_api.APIError.from(\"BAD_REQUEST\",import_error_codes.EMAIL_OTP_ERROR_CODES.INVALID_OTP);const currentEmailIdentifier=(0,import_utils.toOTPIdentifier)(\"email-verification\",email);if(currentEmailVerificationValue.expiresAt=allowedAttempts){await ctx.context.internalAdapter.deleteVerificationByIdentifier(currentEmailIdentifier);throw import_api.APIError.from(\"FORBIDDEN\",import_error_codes.EMAIL_OTP_ERROR_CODES.TOO_MANY_ATTEMPTS)}if(!await(0,import_otp_token.verifyStoredOTP)(ctx,opts,otpValue,ctx.body.otp)){await ctx.context.internalAdapter.updateVerificationByIdentifier(currentEmailIdentifier,{value:`${otpValue}:${parseInt(attempts||\"0\")+1}`});throw import_api.APIError.from(\"BAD_REQUEST\",import_error_codes.EMAIL_OTP_ERROR_CODES.INVALID_OTP)}await ctx.context.internalAdapter.deleteVerificationByIdentifier(currentEmailIdentifier)}else if(ctx.body.otp)ctx.context.logger.warn(\"OTP provided but not required for verifying current email. If you want to require OTP verification for current email, please set the changeEmail.verifyCurrentEmail option to true in the configuration\");const otp=opts.generateOTP({email:newEmail,type:\"change-email\"},ctx)||defaultOTPGenerator(opts);const storedOTP=await(0,import_otp_token.storeOTP)(ctx,opts,otp);await ctx.context.internalAdapter.createVerificationValue({value:`${storedOTP}:0`,identifier:(0,import_utils.toOTPIdentifier)(\"change-email\",`${email}-${newEmail}`),expiresAt:(0,import_date.getDate)(opts.expiresIn,\"sec\")});if(await ctx.context.internalAdapter.findUserByEmail(newEmail)){await ctx.context.internalAdapter.deleteVerificationByIdentifier((0,import_utils.toOTPIdentifier)(\"change-email\",`${email}-${newEmail}`));return ctx.json({success:true})}await ctx.context.runInBackgroundOrAwait(opts.sendVerificationOTP({email:newEmail,otp,type:\"change-email\"},ctx));return ctx.json({success:true})}),\"requestEmailChangeEmailOTP\");const changeEmailEmailOTPBodySchema=z.object({newEmail:z.string().meta({description:\"New email address to verify and change to\"}),otp:z.string().meta({description:\"OTP sent to the new email\"})});const changeEmailEmailOTP=__name(opts=>(0,import_api2.createAuthEndpoint)(\"/email-otp/change-email\",{method:\"POST\",body:changeEmailEmailOTPBodySchema,use:[import_session.sensitiveSessionMiddleware],metadata:{openapi:{operationId:\"changeEmailWithEmailOTP\",description:\"Verify new email with OTP and change the email if verification is successful\",responses:{200:{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{success:{type:\"boolean\"}}}}}}}}}},async ctx=>{if(!opts.changeEmail?.enabled){ctx.context.logger.error(\"Change email with OTP is disabled.\");throw import_api.APIError.fromStatus(\"BAD_REQUEST\",{message:\"Change email with OTP is disabled\"})}const session=ctx.context.session;const email=session.user.email.toLowerCase();const newEmail=ctx.body.newEmail.toLowerCase();if(!z.email().safeParse(newEmail).success)throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.INVALID_EMAIL);if(newEmail===email){ctx.context.logger.error(\"Email is the same\");throw import_api.APIError.fromStatus(\"BAD_REQUEST\",{message:\"Email is the same\"})}const verificationValue=await ctx.context.internalAdapter.findVerificationValue((0,import_utils.toOTPIdentifier)(\"change-email\",`${email}-${newEmail}`));if(!verificationValue)throw import_api.APIError.from(\"BAD_REQUEST\",import_error_codes.EMAIL_OTP_ERROR_CODES.INVALID_OTP);const changeEmailIdentifier=(0,import_utils.toOTPIdentifier)(\"change-email\",`${email}-${newEmail}`);if(verificationValue.expiresAt=allowedAttempts){await ctx.context.internalAdapter.deleteVerificationByIdentifier(changeEmailIdentifier);throw import_api.APIError.from(\"FORBIDDEN\",import_error_codes.EMAIL_OTP_ERROR_CODES.TOO_MANY_ATTEMPTS)}if(!await(0,import_otp_token.verifyStoredOTP)(ctx,opts,otpValue,ctx.body.otp)){await ctx.context.internalAdapter.updateVerificationByIdentifier(changeEmailIdentifier,{value:`${otpValue}:${parseInt(attempts||\"0\")+1}`});throw import_api.APIError.from(\"BAD_REQUEST\",import_error_codes.EMAIL_OTP_ERROR_CODES.INVALID_OTP)}await ctx.context.internalAdapter.deleteVerificationByIdentifier(changeEmailIdentifier);const currentUser=await ctx.context.internalAdapter.findUserByEmail(email);if(!currentUser)throw import_api.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.USER_NOT_FOUND);if(await ctx.context.internalAdapter.findUserByEmail(newEmail))throw import_api.APIError.fromStatus(\"BAD_REQUEST\",{message:\"Email already in use\"});if(ctx.context.options.emailVerification?.beforeEmailVerification)await ctx.context.options.emailVerification.beforeEmailVerification(currentUser.user,ctx.request);const updatedUser=await ctx.context.internalAdapter.updateUser(currentUser.user.id,{email:newEmail,emailVerified:true});if(ctx.context.options.emailVerification?.afterEmailVerification)await ctx.context.options.emailVerification.afterEmailVerification(updatedUser,ctx.request);await(0,import_cookies.setSessionCookie)(ctx,{session:session.session,user:{...session.user,email:newEmail,emailVerified:true}});return ctx.json({success:true})}),\"changeEmailEmailOTP\");const defaultOTPGenerator=__name(options=>(0,import_random.generateRandomString)(options.otpLength??6,\"0-9\"),\"defaultOTPGenerator\");async function atomicVerifyOTP(ctx,opts,identifier,providedOTP){const verificationValue=await ctx.context.internalAdapter.findVerificationValue(identifier);if(!verificationValue)throw import_api.APIError.from(\"BAD_REQUEST\",import_error_codes.EMAIL_OTP_ERROR_CODES.INVALID_OTP);if(verificationValue.expiresAt=allowedAttempts){await ctx.context.internalAdapter.deleteVerificationByIdentifier(identifier);throw import_api.APIError.from(\"FORBIDDEN\",import_error_codes.EMAIL_OTP_ERROR_CODES.TOO_MANY_ATTEMPTS)}await ctx.context.internalAdapter.deleteVerificationByIdentifier(identifier);if(!await(0,import_otp_token.verifyStoredOTP)(ctx,opts,otpValue,providedOTP)){await ctx.context.internalAdapter.createVerificationValue({value:`${otpValue}:${parseInt(attempts||\"0\")+1}`,identifier,expiresAt:verificationValue.expiresAt});throw import_api.APIError.from(\"BAD_REQUEST\",import_error_codes.EMAIL_OTP_ERROR_CODES.INVALID_OTP)}}__name(atomicVerifyOTP,\"atomicVerifyOTP\");0&&(module.exports={changeEmailEmailOTP,checkVerificationOTP,createVerificationOTP,forgetPasswordEmailOTP,getVerificationOTP,requestEmailChangeEmailOTP,requestPasswordResetEmailOTP,resetPasswordEmailOTP,sendVerificationOTP,signInEmailOTP,verifyEmailOTP});\n})()\n","warnings":[],"map":{"version":3,"mappings":";i/BAAA,2mBAAwB,gCACxB,kBAAg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