Edit: /tmp/tsx-0/17887-569cba9a4dc0c31fc4bf1cfd9b1bdd85d2bfd331 (14488B)
{"code":"__filename=\"/opt/canhelp/node_modules/better-auth/dist/api/routes/password.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 password_exports={};__export(password_exports,{requestPasswordReset:()=>requestPasswordReset,requestPasswordResetCallback:()=>requestPasswordResetCallback,resetPassword:()=>resetPassword,verifyPassword:()=>verifyPassword});module.exports=__toCommonJS(password_exports);var import_origin_check=require(\"../middlewares/origin-check.mjs\");var import_middlewares=require(\"../middlewares/index.mjs\");var import_date=require(\"../../utils/date.mjs\");var import_session=require(\"./session.mjs\");var import_password=require(\"../../utils/password.mjs\");var import_error=require(\"@better-auth/core/error\");var import_id=require(\"@better-auth/core/utils/id\");var import_api=require(\"@better-auth/core/api\");var z=__toESM(require(\"zod\"));function redirectError(ctx,callbackURL,query){const url=callbackURL?new URL(callbackURL,ctx.baseURL):new URL(`${ctx.baseURL}/error`);if(query)Object.entries(query).forEach(([k,v])=>url.searchParams.set(k,v));return url.href}__name(redirectError,\"redirectError\");function redirectCallback(ctx,callbackURL,query){const url=new URL(callbackURL,ctx.baseURL);if(query)Object.entries(query).forEach(([k,v])=>url.searchParams.set(k,v));return url.href}__name(redirectCallback,\"redirectCallback\");const requestPasswordReset=(0,import_api.createAuthEndpoint)(\"/request-password-reset\",{method:\"POST\",body:z.object({email:z.email().meta({description:\"The email address of the user to send a password reset email to\"}),redirectTo:z.string().meta({description:\"The URL to redirect the user to reset their password. If the token isn't valid or expired, it'll be redirected with a query parameter `?error=INVALID_TOKEN`. If the token is valid, it'll be redirected with a query parameter `?token=VALID_TOKEN\"}).optional()}),metadata:{openapi:{operationId:\"requestPasswordReset\",description:\"Send a password reset email to the user\",responses:{\"200\":{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{status:{type:\"boolean\"},message:{type:\"string\"}}}}}}}}},use:[(0,import_origin_check.originCheck)(ctx=>ctx.body.redirectTo)]},async ctx=>{if(!ctx.context.options.emailAndPassword?.sendResetPassword){ctx.context.logger.error(\"Reset password isn't enabled.Please pass an emailAndPassword.sendResetPassword function in your auth config!\");throw import_error.APIError.from(\"BAD_REQUEST\",{message:\"Reset password isn't enabled\",code:\"RESET_PASSWORD_DISABLED\"})}const{email,redirectTo}=ctx.body;const user=await ctx.context.internalAdapter.findUserByEmail(email,{includeAccounts:true});if(!user){(0,import_id.generateId)(24);await ctx.context.internalAdapter.findVerificationValue(\"dummy-verification-token\");ctx.context.logger.error(\"Reset Password: User not found\",{email});return ctx.json({status:true,message:\"If this email exists in our system, check your email for the reset link\"})}const expiresAt=(0,import_date.getDate)(ctx.context.options.emailAndPassword.resetPasswordTokenExpiresIn||3600*1,\"sec\");const verificationToken=(0,import_id.generateId)(24);await ctx.context.internalAdapter.createVerificationValue({value:user.user.id,identifier:`reset-password:${verificationToken}`,expiresAt});const callbackURL=redirectTo?encodeURIComponent(redirectTo):\"\";const url=`${ctx.context.baseURL}/reset-password/${verificationToken}?callbackURL=${callbackURL}`;await ctx.context.runInBackgroundOrAwait(ctx.context.options.emailAndPassword.sendResetPassword({user:user.user,url,token:verificationToken},ctx.request));return ctx.json({status:true,message:\"If this email exists in our system, check your email for the reset link\"})});const requestPasswordResetCallback=(0,import_api.createAuthEndpoint)(\"/reset-password/:token\",{method:\"GET\",operationId:\"forgetPasswordCallback\",query:z.object({callbackURL:z.string().meta({description:\"The URL to redirect the user to reset their password\"})}),use:[(0,import_origin_check.originCheck)(ctx=>ctx.query.callbackURL)],metadata:{openapi:{operationId:\"resetPasswordCallback\",description:\"Redirects the user to the callback URL with the token\",parameters:[{name:\"token\",in:\"path\",required:true,description:\"The token to reset the password\",schema:{type:\"string\"}},{name:\"callbackURL\",in:\"query\",required:true,description:\"The URL to redirect the user to reset their password\",schema:{type:\"string\"}}],responses:{\"200\":{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{token:{type:\"string\"}}}}}}}}}},async ctx=>{const{token}=ctx.params;const{callbackURL}=ctx.query;if(!token||!callbackURL)throw ctx.redirect(redirectError(ctx.context,callbackURL,{error:\"INVALID_TOKEN\"}));const verification=await ctx.context.internalAdapter.findVerificationValue(`reset-password:${token}`);if(!verification||verification.expiresAt
{const token=ctx.body.token||ctx.query?.token;if(!token)throw import_error.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.INVALID_TOKEN);const{newPassword}=ctx.body;const minLength=ctx.context.password?.config.minPasswordLength;const maxLength=ctx.context.password?.config.maxPasswordLength;if(newPassword.lengthmaxLength)throw import_error.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.PASSWORD_TOO_LONG);const id=`reset-password:${token}`;const verification=await ctx.context.internalAdapter.findVerificationValue(id);if(!verification||verification.expiresAtac.providerId===\"credential\"))await ctx.context.internalAdapter.createAccount({userId,providerId:\"credential\",password:hashedPassword,accountId:userId});else await ctx.context.internalAdapter.updatePassword(userId,hashedPassword);await ctx.context.internalAdapter.deleteVerificationByIdentifier(id);if(ctx.context.options.emailAndPassword?.onPasswordReset){const user=await ctx.context.internalAdapter.findUserById(userId);if(user)await ctx.context.options.emailAndPassword.onPasswordReset({user},ctx.request)}if(ctx.context.options.emailAndPassword?.revokeSessionsOnPasswordReset)await ctx.context.internalAdapter.deleteSessions(userId);return ctx.json({status:true})});const verifyPassword=(0,import_api.createAuthEndpoint)(\"/verify-password\",{method:\"POST\",body:z.object({password:z.string().meta({description:\"The password to verify\"})}),metadata:{scope:\"server\",openapi:{operationId:\"verifyPassword\",description:\"Verify the current user's password\",responses:{\"200\":{description:\"Success\",content:{\"application/json\":{schema:{type:\"object\",properties:{status:{type:\"boolean\"}}}}}}}}},use:[import_session.sensitiveSessionMiddleware]},async ctx=>{const{password}=ctx.body;const session=ctx.context.session;if(!await(0,import_password.validatePassword)(ctx,{password,userId:session.user.id}))throw import_error.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.INVALID_PASSWORD);return ctx.json({status:true})});0&&(module.exports={requestPasswordReset,requestPasswordResetCallback,resetPassword,verifyPassword});\n})()\n","warnings":[],"map":{"version":3,"mappings":";i/BAAA,ySAA4B,2CAC5B,uBAAO,oCACP,gBAAwB,gCACxB,mBAA2C,yBAC3C,oBAAiC,oCACjC,iBAA2C,mCAC3C,cAA2B,sCAC3B,eAAmC,iCACnC,MAAmB,wBAGnB,SAAS,cAAc,IAAK,YAAa,MAAO,CAC/C,MAAM,IAAM,YAAc,IAAI,IAAI,YAAa,IAAI,OAAO,EAAI,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,EAC5F,GAAI,MAAO,OAAO,QAAQ,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAG,CAAC,IAAM,IAAI,aAAa,IAAI,EAAG,CAAC,CAAC,EAC/E,OAAO,IAAI,IACZ,CAJS,sCAKT,SAAS,iBAAiB,IAAK,YAAa,MAAO,CAClD,MAAM,IAAM,IAAI,IAAI,YAAa,IAAI,OAAO,EAC5C,GAAI,MAAO,OAAO,QAAQ,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAG,CAAC,I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