Edit: /tmp/tsx-0/17887-f069d7c49822ce13b25d93b97468595602c09c1a (6909B)
{"code":"__filename=\"/opt/canhelp/node_modules/better-auth/dist/plugins/one-tap/index.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 one_tap_exports={};__export(one_tap_exports,{oneTap:()=>oneTap});module.exports=__toCommonJS(one_tap_exports);var import_schema=require(\"../../db/schema.mjs\");var import_cookies=require(\"../../cookies/index.mjs\");var import_api=require(\"../../api/index.mjs\");var import_boolean=require(\"../../utils/boolean.mjs\");var import_api2=require(\"@better-auth/core/api\");var z=__toESM(require(\"zod\"));var import_jose=require(\"jose\");const oneTapCallbackBodySchema=z.object({idToken:z.string().meta({description:\"Google ID token, which the client obtains from the One Tap API\"})});const oneTap=__name(options=>({id:\"one-tap\",endpoints:{oneTapCallback:(0,import_api2.createAuthEndpoint)(\"/one-tap/callback\",{method:\"POST\",body:oneTapCallbackBodySchema,metadata:{openapi:{summary:\"One tap callback\",description:\"Use this endpoint to authenticate with Google One Tap\",responses:{200:{description:\"Successful response\",content:{\"application/json\":{schema:{type:\"object\",properties:{session:{$ref:\"#/components/schemas/Session\"},user:{$ref:\"#/components/schemas/User\"}}}}}},400:{description:\"Invalid token\"}}}}},async ctx=>{const{idToken}=ctx.body;let payload;try{const JWKS=(0,import_jose.createRemoteJWKSet)(new URL(\"https://www.googleapis.com/oauth2/v3/certs\"));const googleProvider=typeof ctx.context.options.socialProviders?.google===\"function\"?await ctx.context.options.socialProviders?.google():ctx.context.options.socialProviders?.google;const{payload:verifiedPayload}=await(0,import_jose.jwtVerify)(idToken,JWKS,{issuer:[\"https://accounts.google.com\",\"accounts.google.com\"],audience:options?.clientId||googleProvider?.clientId});payload=verifiedPayload}catch{throw new import_api.APIError(\"BAD_REQUEST\",{message:\"invalid id token\"})}const{email,email_verified,name,picture,sub}=payload;if(!email)return ctx.json({error:\"Email not available in token\"});const user=await ctx.context.internalAdapter.findUserByEmail(email);if(!user){if(options?.disableSignup)throw new import_api.APIError(\"BAD_GATEWAY\",{message:\"User not found\"});const newUser=await ctx.context.internalAdapter.createOAuthUser({email,emailVerified:typeof email_verified===\"boolean\"?email_verified:(0,import_boolean.toBoolean)(email_verified),name,image:picture},{providerId:\"google\",accountId:sub});if(!newUser)throw new import_api.APIError(\"INTERNAL_SERVER_ERROR\",{message:\"Could not create user\"});const session2=await ctx.context.internalAdapter.createSession(newUser.user.id);await(0,import_cookies.setSessionCookie)(ctx,{user:newUser.user,session:session2});return ctx.json({token:session2.token,user:(0,import_schema.parseUserOutput)(ctx.context.options,newUser.user)})}if(!await ctx.context.internalAdapter.findAccount(sub))if(ctx.context.options.account?.accountLinking?.enabled!==false&&(ctx.context.trustedProviders.includes(\"google\")||email_verified))await ctx.context.internalAdapter.linkAccount({userId:user.user.id,providerId:\"google\",accountId:sub,scope:\"openid,profile,email\",idToken});else throw new import_api.APIError(\"UNAUTHORIZED\",{message:\"Google sub doesn't match\"});const session=await ctx.context.internalAdapter.createSession(user.user.id);await(0,import_cookies.setSessionCookie)(ctx,{user:user.user,session});return ctx.json({token:session.token,user:(0,import_schema.parseUserOutput)(ctx.context.options,user.user)})})},options}),\"oneTap\");0&&(module.exports={oneTap});\n})()\n","warnings":[],"map":{"version":3,"mappings":";i/BAAA,oIAAgC,+BAChC,mBAAiC,mCACjC,eAAyB,+BACzB,mBAA0B,mCAC1B,IAAAA,YAAmC,iCACnC,MAAmB,wBACnB,gBAA8C,gBAG9C,MAAM,yBAA2B,EAAE,OAAO,CAAE,QAAS,EAAE,OAAO,EAAE,KAAK,CAAE,YAAa,gEAAiE,CAAC,CAAE,CAAC,EACzJ,MAAM,OAAS,OAAC,UAAa,CAC5B,GAAI,UACJ,UAAW,CAAE,kBAAgB,gCAAmB,oBAAqB,CACpE,OAAQ,OACR,KAAM,yBACN,SAAU,CAAE,QAAS,CACpB,QAAS,mBACT,YAAa,wDACb,UAAW,CACV,IAAK,CACJ,YAAa,sBACb,QAAS,CAAE,mBAAoB,CAAE,OAAQ,CACxC,KAAM,SACN,WAAY,CACX,QAAS,CAAE,KAAM,8BAA+B,EAChD,KAAM,CAAE,KAAM,2BAA4B,CAC3C,CACD,CAAE,CAAE,CACL,EACA,IAAK,CAAE,YAAa,eAAgB,CACrC,CACD,CAAE,CACH,EAAG,MAAO,KAAQ,CACjB,KAAM,CAAE,OAAQ,EAAI,IAAI,KACxB,IAAI,QACJ,GAAI,CACH,MAAM,QAAO,gCAAmB,IAAI,IAAI,4CAA4C,CAAC,EACrF,MAAM,eAAiB,OAAO,IAAI,QAAQ,QAAQ,iBAAiB,SAAW,WAAa,MAAM,IAAI,QAAQ,QAAQ,iBAAiB,OAAO,EAAI,IAAI,QAAQ,QAAQ,iBAAiB,OACtL,KAAM,CAAE,QAAS,eAAgB,EAAI,QAAM,uBAAU,QAAS,KAAM,CACnE,OAAQ,CAAC,8BAA+B,qBAAqB,EAC7D,SAAU,SAAS,UAAY,gBAAgB,QAChD,CAAC,EACD,QAAU,eACX,MAAQ,CACP,MAAM,IAAI,oBAAS,cAAe,CAAE,QAAS,kBAAmB,CAAC,C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