"use strict";(()=>{var e={};e.id=2738,e.ids=[2738],e.modules={76154:e=>{e.exports=require("google-auth-library")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},41620:(e,r,t)=>{t.r(r),t.d(r,{config:()=>f,default:()=>p,routeModule:()=>m});var n={};t.r(n),t.d(n,{default:()=>g});var i=t(89947),s=t(2706),o=t(96762),a=t(48225),l=t.n(a),u=t(77619),c=t.n(u);let{OAuth2Client:d}=t(76154);async function g(e,r){if("POST"!==e.method)return r.json({success:!1,payload:null,msg:"Failed!"});try{let t=e.headers.authorization,n=c()({key:t,user_id:String(e.query.user_id)});if(!n?.user_id)throw Error("Api Credentials invalid!");if(!n.full_access||!n.sign)return r.json({success:!1,payload:null,msg:"Unauthorized"});let{token:i,clientId:s}=e.body,o=new d(s),a=await o.verifyIdToken({idToken:i,audience:s});if(!a?.getPayload()?.email_verified)return r.json({success:!1,payload:null,msg:"User not verified!"});let l=a.getPayload();r.json({success:!0,payload:l})}catch(t){l()({component:"/api/user/grab-google-user-from-token/main-catch-error",message:t.message,req:e}),r.json({success:!1,payload:null,msg:"User fetch Error"})}}let p=(0,o.M)(n,"default"),f=(0,o.M)(n,"config"),m=new i.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/user/[user_id]/grab-google-user-from-token",pathname:"/api/user/[user_id]/grab-google-user-from-token",bundlePath:"",filename:""},userland:n})},77619:(e,r,t)=>{let n=t(29021),i=t(72835);e.exports=({key:e,database:r,table:t,user_id:s})=>{if(!e||!s)return null;try{let o=process.env.DSQL_API_KEYS_PATH;if(!o)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let a=i({encryptedString:e}),l=JSON.parse(a||""),u=n.existsSync(`${o}/${l.sign}`);if(String(l.user_id)!==String(s)||!u)return null;if(!l.target_database)return l;if(!r&&l.target_database)return null;let c=l.target_database?.split(",").includes(String(r));if(c&&!l.target_table)return l;if(c&&!t&&l.target_table)return null;if(l.target_table?.split(",").includes(String(t)))return l;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),null}}},48225:(e,r,t)=>{let n=t(29021),{IncomingMessage:i}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:i,req:s}){let o=new Date,a=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||n||r||s.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let i=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(i+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),s?.url&&(i+=`
URL: ${s.url}`),s?.body&&(i+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),a&&(i+=`
IP: ${a}`),i+=`
Date: ${o.toDateString()}
========================================`,n.existsSync("./.tmp/error.log")||n.writeFileSync("./.tmp/error.log","","utf-8");let l=n.readFileSync("./.tmp/error.log","utf-8");n.writeFileSync("./.tmp/error.log",i),n.appendFileSync("./.tmp/error.log",`




${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},72835:(e,r,t)=>{let{scryptSync:n,createDecipheriv:i}=t(55511),{Buffer:s}=t(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let o=r||process.env.DSQL_ENCRYPTION_PASSWORD,a=t||process.env.DSQL_ENCRYPTION_SALT,l=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!o?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let u=i("aes-192-cbc",n(o,a,l),s.alloc(16,0));try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},2706:(e,r)=>{var t;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../../../webpack-api-runtime.js");r.C(e);var t=r(r.s=41620);module.exports=t})();