Edit: /tmp/tsx-0/17887-0a186386a6a31e66f006c1de06f35f31e9137688 (14520B)
{"code":"__filename=\"/opt/canhelp/node_modules/better-auth/dist/api/routes/sign-up.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 sign_up_exports={};__export(sign_up_exports,{signUpEmail:()=>signUpEmail});module.exports=__toCommonJS(sign_up_exports);var import_is_api_error=require(\"../../utils/is-api-error.mjs\");var import_origin_check=require(\"../middlewares/origin-check.mjs\");var import_schema=require(\"../../db/schema.mjs\");var import_db=require(\"../../db/index.mjs\");var import_cookies=require(\"../../cookies/index.mjs\");var import_email_verification=require(\"./email-verification.mjs\");var import_context=require(\"@better-auth/core/context\");var import_env=require(\"@better-auth/core/env\");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\"));const signUpEmailBodySchema=z.object({name:z.string(),email:z.email(),password:z.string().nonempty(),image:z.string().optional(),callbackURL:z.string().optional(),rememberMe:z.boolean().optional()}).and(z.record(z.string(),z.any()));const signUpEmail=__name(()=>(0,import_api.createAuthEndpoint)(\"/sign-up/email\",{method:\"POST\",operationId:\"signUpWithEmailAndPassword\",use:[import_origin_check.formCsrfMiddleware],body:signUpEmailBodySchema,metadata:{allowedMediaTypes:[\"application/x-www-form-urlencoded\",\"application/json\"],$Infer:{body:{},returned:{}},openapi:{operationId:\"signUpWithEmailAndPassword\",description:\"Sign up a user using email and password\",requestBody:{content:{\"application/json\":{schema:{type:\"object\",properties:{name:{type:\"string\",description:\"The name of the user\"},email:{type:\"string\",description:\"The email of the user\"},password:{type:\"string\",description:\"The password of the user\"},image:{type:\"string\",description:\"The profile image URL of the user\"},callbackURL:{type:\"string\",description:\"The URL to use for email verification callback\"},rememberMe:{type:\"boolean\",description:\"If this is false, the session will not be remembered. Default is `true`.\"}},required:[\"name\",\"email\",\"password\"]}}}},responses:{\"200\":{description:\"Successfully created user\",content:{\"application/json\":{schema:{type:\"object\",properties:{token:{type:\"string\",nullable:true,description:\"Authentication token for the session\"},user:{type:\"object\",properties:{id:{type:\"string\",description:\"The unique identifier of the user\"},email:{type:\"string\",format:\"email\",description:\"The email address of the user\"},name:{type:\"string\",description:\"The name of the user\"},image:{type:\"string\",format:\"uri\",nullable:true,description:\"The profile image URL of the user\"},emailVerified:{type:\"boolean\",description:\"Whether the email has been verified\"},createdAt:{type:\"string\",format:\"date-time\",description:\"When the user was created\"},updatedAt:{type:\"string\",format:\"date-time\",description:\"When the user was last updated\"}},required:[\"id\",\"email\",\"name\",\"emailVerified\",\"createdAt\",\"updatedAt\"]}},required:[\"user\"]}}}},\"422\":{description:\"Unprocessable Entity. User already exists or failed to create user.\",content:{\"application/json\":{schema:{type:\"object\",properties:{message:{type:\"string\"}}}}}}}}}},async ctx=>{return(0,import_context.runWithTransaction)(ctx.context.adapter,async()=>{if(!ctx.context.options.emailAndPassword?.enabled||ctx.context.options.emailAndPassword?.disableSignUp)throw import_error.APIError.from(\"BAD_REQUEST\",{message:\"Email and password sign up is not enabled\",code:\"EMAIL_PASSWORD_SIGN_UP_DISABLED\"});const body=ctx.body;const{name,email,password,image,callbackURL:_callbackURL,rememberMe,...rest}=body;if(!z.email().safeParse(email).success)throw import_error.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.INVALID_EMAIL);if(!password||typeof password!==\"string\")throw import_error.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.INVALID_PASSWORD);const minPasswordLength=ctx.context.password.config.minPasswordLength;if(password.length
maxPasswordLength){ctx.context.logger.error(\"Password is too long\");throw import_error.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.PASSWORD_TOO_LONG)}const shouldReturnGenericDuplicateResponse=ctx.context.options.emailAndPassword.requireEmailVerification;const shouldSkipAutoSignIn=ctx.context.options.emailAndPassword.autoSignIn===false||shouldReturnGenericDuplicateResponse;const additionalUserFields=(0,import_schema.parseUserInput)(ctx.context.options,rest,\"create\");const normalizedEmail=email.toLowerCase();const dbUser=await ctx.context.internalAdapter.findUserByEmail(normalizedEmail);if(dbUser?.user){ctx.context.logger.info(`Sign-up attempt for existing email: ${email}`);if(shouldReturnGenericDuplicateResponse){await ctx.context.password.hash(password);if(ctx.context.options.emailAndPassword?.onExistingUserSignUp)await ctx.context.runInBackgroundOrAwait(ctx.context.options.emailAndPassword.onExistingUserSignUp({user:dbUser.user},ctx.request));const now=new Date;const generatedId=ctx.context.generateId({model:\"user\"})||(0,import_id.generateId)();const coreFields={name,email:normalizedEmail,emailVerified:false,image:image||null,createdAt:now,updatedAt:now};const customSyntheticUser=ctx.context.options.emailAndPassword?.customSyntheticUser;let syntheticUser;if(customSyntheticUser){const additionalFieldKeys=Object.keys(ctx.context.options.user?.additionalFields??{});const additionalFields={};for(const key of additionalFieldKeys)if(key in additionalUserFields)additionalFields[key]=additionalUserFields[key];syntheticUser=customSyntheticUser({coreFields,additionalFields,id:generatedId})}else syntheticUser={...coreFields,...additionalUserFields,id:generatedId};return ctx.json({token:null,user:(0,import_schema.parseUserOutput)(ctx.context.options,syntheticUser)})}throw import_error.APIError.from(\"UNPROCESSABLE_ENTITY\",import_error.BASE_ERROR_CODES.USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL)}const hash=await ctx.context.password.hash(password);let createdUser;try{createdUser=await ctx.context.internalAdapter.createUser({email:normalizedEmail,name,image,...additionalUserFields,emailVerified:false});if(!createdUser)throw import_error.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.FAILED_TO_CREATE_USER)}catch(e){if((0,import_env.isDevelopment)())ctx.context.logger.error(\"Failed to create user\",e);if((0,import_is_api_error.isAPIError)(e))throw e;ctx.context.logger?.error(\"Failed to create user\",e);throw import_error.APIError.from(\"UNPROCESSABLE_ENTITY\",import_error.BASE_ERROR_CODES.FAILED_TO_CREATE_USER)}if(!createdUser)throw import_error.APIError.from(\"UNPROCESSABLE_ENTITY\",import_error.BASE_ERROR_CODES.FAILED_TO_CREATE_USER);await ctx.context.internalAdapter.linkAccount({userId:createdUser.id,providerId:\"credential\",accountId:createdUser.id,password:hash});if(ctx.context.options.emailVerification?.sendOnSignUp??ctx.context.options.emailAndPassword.requireEmailVerification){const token=await(0,import_email_verification.createEmailVerificationToken)(ctx.context.secret,createdUser.email,void 0,ctx.context.options.emailVerification?.expiresIn);const callbackURL=body.callbackURL?encodeURIComponent(body.callbackURL):encodeURIComponent(\"/\");const url=`${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${callbackURL}`;if(ctx.context.options.emailVerification?.sendVerificationEmail)await ctx.context.runInBackgroundOrAwait(ctx.context.options.emailVerification.sendVerificationEmail({user:createdUser,url,token},ctx.request))}if(shouldSkipAutoSignIn)return ctx.json({token:null,user:(0,import_schema.parseUserOutput)(ctx.context.options,createdUser)});const session=await ctx.context.internalAdapter.createSession(createdUser.id,rememberMe===false);if(!session)throw import_error.APIError.from(\"BAD_REQUEST\",import_error.BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION);await(0,import_cookies.setSessionCookie)(ctx,{session,user:createdUser},rememberMe===false);return ctx.json({token:session.token,user:(0,import_schema.parseUserOutput)(ctx.context.options,createdUser)})})}),\"signUpEmail\");0&&(module.exports={signUpEmail});\n})()\n","warnings":[],"map":{"version":3,"mappings":";i/BAAA,oJAA2B,wCAC3B,wBAAmC,2CACnC,kBAAgD,+BAChD,cAAO,8BACP,mBAAiC,mCACjC,8BAA6C,oCAC7C,mBAAmC,qCACnC,eAA8B,iCAC9B,iBAA2C,mCAC3C,cAA2B,sCAC3B,eAAmC,iCACnC,MAAmB,wBAGnB,MAAM,sBAAwB,EAAE,OAAO,CACtC,KAAM,EAAE,OAAO,EACf,MAAO,EAAE,MAAM,EACf,SAAU,EAAE,OAAO,EAAE,SAAS,EAC9B,MAAO,EAAE,OAAO,EAAE,SAAS,EAC3B,YAAa,EAAE,OAAO,EAAE,SAAS,EACjC,WAAY,EAAE,QAAQ,EAAE,SAAS,CAClC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAG,EAAE,IAAI,CAAC,CAAC,EACpC,MAAM,YAAc,cAAM,+BAAmB,iBAAkB,CAC9D,OAAQ,OACR,YAAa,6BACb,IAAK,CAAC,sCAAkB,EACxB,KAAM,sBACN,SAAU,CACT,kBAAmB,CAAC,oCAAqC,kBAAkB,EAC3E,OAAQ,CACP,KAAM,CAAC,EACP,SAAU,CAAC,CACZ,EACA,QAAS,CACR,YAAa,6BACb,YAAa,0CACb,YAAa,CAAE,QAAS,CAAE,mBAAoB,CAAE,OAAQ,CACvD,KAAM,SACN,WAAY,CACX,KAAM,CACL,KAAM,SACN,YAAa,sBACd,EACA,MAAO,CACN,KAAM,SACN,YAAa,uBACd,EACA,SAAU,CACT,KAAM,SACN,YAAa,0BACd,EACA,MAAO,CACN,KAAM,SACN,YAAa,mCACd,EACA,YAAa,CACZ,KAAM,SACN,YAAa,gDACd,EACA,WAAY,CACX,KAAM,UACN,YAAa,0EACd,CACD,EACA,SAAU,CACT,OACA,QACA,UACD,CACD,CAAE,CAAE,CAAE,EAC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