Edit: /tmp/tsx-0/17887-3b7f452b43d7bc6d08751f77fd26b27d8c85955b (7682B)
{"code":"__filename=\"/opt/canhelp/node_modules/better-auth/dist/state.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 state_exports={};__export(state_exports,{StateError:()=>StateError,generateGenericState:()=>generateGenericState,parseGenericState:()=>parseGenericState});module.exports=__toCommonJS(state_exports);var import_random=require(\"./crypto/random.mjs\");var import_crypto=require(\"./crypto/index.mjs\");var import_cookies=require(\"./cookies/index.mjs\");var import_error=require(\"@better-auth/core/error\");var z=__toESM(require(\"zod\"));const stateDataSchema=z.looseObject({callbackURL:z.string(),codeVerifier:z.string(),errorURL:z.string().optional(),newUserURL:z.string().optional(),expiresAt:z.number(),link:z.object({email:z.string(),userId:z.coerce.string()}).optional(),requestSignUp:z.boolean().optional()});var StateError=class extends import_error.BetterAuthError{static{__name(this,\"StateError\")}code;details;constructor(message,options){super(message,options);this.code=options.code;this.details=options.details}};async function generateGenericState(c,stateData,settings){const state=(0,import_random.generateRandomString)(32);if(c.context.oauthConfig.storeStateStrategy===\"cookie\"){const encryptedData=await(0,import_crypto.symmetricEncrypt)({key:c.context.secretConfig,data:JSON.stringify(stateData)});const stateCookie2=c.context.createAuthCookie(settings?.cookieName??\"oauth_state\",{maxAge:600});c.setCookie(stateCookie2.name,encryptedData,stateCookie2.attributes);return{state,codeVerifier:stateData.codeVerifier}}const stateCookie=c.context.createAuthCookie(settings?.cookieName??\"state\",{maxAge:300});await c.setSignedCookie(stateCookie.name,state,c.context.secret,stateCookie.attributes);const expiresAt=new Date;expiresAt.setMinutes(expiresAt.getMinutes()+10);const verification=await c.context.internalAdapter.createVerificationValue({value:JSON.stringify(stateData),identifier:state,expiresAt});if(!verification)throw new StateError(\"Unable to create verification. Make sure the database adapter is properly working and there is a verification table in the database\",{code:\"state_generation_error\"});return{state:verification.identifier,codeVerifier:stateData.codeVerifier}}__name(generateGenericState,\"generateGenericState\");async function parseGenericState(c,state,settings){const storeStateStrategy=c.context.oauthConfig.storeStateStrategy;let parsedData;if(storeStateStrategy===\"cookie\"){const stateCookie=c.context.createAuthCookie(settings?.cookieName??\"oauth_state\");const encryptedData=c.getCookie(stateCookie.name);if(!encryptedData)throw new StateError(\"State mismatch: auth state cookie not found\",{code:\"state_mismatch\",details:{state}});try{const decryptedData=await(0,import_crypto.symmetricDecrypt)({key:c.context.secretConfig,data:encryptedData});parsedData=stateDataSchema.parse(JSON.parse(decryptedData))}catch(error){throw new StateError(\"State invalid: Failed to decrypt or parse auth state\",{code:\"state_invalid\",details:{state},cause:error})}(0,import_cookies.expireCookie)(c,stateCookie)}else{const data=await c.context.internalAdapter.findVerificationValue(state);if(!data)throw new StateError(\"State mismatch: verification not found\",{code:\"state_mismatch\",details:{state}});parsedData=stateDataSchema.parse(JSON.parse(data.value));const stateCookie=c.context.createAuthCookie(settings?.cookieName??\"state\");const stateCookieValue=await c.getSignedCookie(stateCookie.name,c.context.secret);if(!c.context.oauthConfig.skipStateCookieCheck&&(!stateCookieValue||stateCookieValue!==state))throw new StateError(\"State mismatch: State not persisted correctly\",{code:\"state_security_mismatch\",details:{state}});(0,import_cookies.expireCookie)(c,stateCookie);await c.context.internalAdapter.deleteVerificationByIdentifier(state)}if(parsedData.expiresAt