Edit: /tmp/tsx-0/17887-9f1d425489ff334612a6de21c890f9754e67cb18 (5246B)
{"code":"__filename=\"/opt/canhelp/node_modules/better-auth/dist/plugins/last-login-method/index.mjs\";(()=>{\nvar __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;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 __toCommonJS=mod=>__copyProps(__defProp({},\"__esModule\",{value:true}),mod);var last_login_method_exports={};__export(last_login_method_exports,{lastLoginMethod:()=>lastLoginMethod});module.exports=__toCommonJS(last_login_method_exports);var import_api=require(\"@better-auth/core/api\");const lastLoginMethod=__name(userConfig=>{const defaultResolveMethod=__name(ctx=>{if(ctx.path.startsWith(\"/callback/\")||ctx.path.startsWith(\"/oauth2/callback/\"))return ctx.params?.id||ctx.params?.providerId||ctx.path.split(\"/\").pop();if(ctx.path===\"/sign-in/email\"||ctx.path===\"/sign-up/email\")return\"email\";if(ctx.path.includes(\"siwe\"))return\"siwe\";if(ctx.path.includes(\"/passkey/verify-authentication\"))return\"passkey\";if(ctx.path.startsWith(\"/magic-link/verify\"))return\"magic-link\";return null},\"defaultResolveMethod\");const config={cookieName:\"better-auth.last_used_login_method\",maxAge:3600*24*30,...userConfig};return{id:\"last-login-method\",init(ctx){return{options:{databaseHooks:{user:{create:{async before(user,context){if(!config.storeInDatabase)return;if(!context)return;const lastUsedLoginMethod=config.customResolveMethod?.(context)??defaultResolveMethod(context);if(lastUsedLoginMethod)return{data:{...user,lastLoginMethod:lastUsedLoginMethod}}}}},session:{create:{async after(session,context){if(!config.storeInDatabase)return;if(!context)return;const lastUsedLoginMethod=config.customResolveMethod?.(context)??defaultResolveMethod(context);if(lastUsedLoginMethod&&session?.userId)try{await ctx.internalAdapter.updateUser(session.userId,{lastLoginMethod:lastUsedLoginMethod})}catch(error){ctx.logger.error(\"Failed to update lastLoginMethod\",error)}}}}}}}},hooks:{after:[{matcher(){return true},handler:(0,import_api.createAuthMiddleware)(async ctx=>{const lastUsedLoginMethod=config.customResolveMethod?.(ctx)??defaultResolveMethod(ctx);if(lastUsedLoginMethod){const setCookieHeaders=ctx.context.responseHeaders?.getSetCookie?.()||[];const sessionTokenName=ctx.context.authCookies.sessionToken.name;if(setCookieHeaders.some(cookie=>cookie.includes(sessionTokenName))){const cookieAttributes={...ctx.context.authCookies.sessionToken.attributes,maxAge:config.maxAge,httpOnly:false};ctx.setCookie(config.cookieName,lastUsedLoginMethod,cookieAttributes)}}})}]},schema:config.storeInDatabase?{user:{fields:{lastLoginMethod:{type:\"string\",input:false,required:false,fieldName:config.schema?.user?.lastLoginMethod||\"lastLoginMethod\"}}}}:void 0,options:userConfig}},\"lastLoginMethod\");0&&(module.exports={lastLoginMethod});\n})()\n","warnings":[],"map":{"version":3,"mappings":";suBAAA,iLAAqC,iCAMrC,MAAM,gBAAkB,OAAC,YAAe,CACvC,MAAM,qBAAuB,OAAC,KAAQ,CACrC,GAAI,IAAI,KAAK,WAAW,YAAY,GAAK,IAAI,KAAK,WAAW,mBAAmB,EAAG,OAAO,IAAI,QAAQ,IAAM,IAAI,QAAQ,YAAc,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI,EAC9J,GAAI,IAAI,OAAS,kBAAoB,IAAI,OAAS,iBAAkB,MAAO,QAC3E,GAAI,IAAI,KAAK,SAAS,MAAM,EAAG,MAAO,OACtC,GAAI,IAAI,KAAK,SAAS,gCAAgC,EAAG,MAAO,UAChE,GAAI,IAAI,KAAK,WAAW,oBAAoB,EAAG,MAAO,aACtD,OAAO,IAC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