"use strict";(()=>{var e={};e.id=5770,e.ids=[5770],e.modules={47795:e=>{e.exports=require("generate-password")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},21572:e=>{e.exports=require("nodemailer")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},55591:e=>{e.exports=require("https")},33873:e=>{e.exports=require("path")},21748:(e,r,t)=>{t.r(r),t.d(r,{config:()=>_,default:()=>m,routeModule:()=>h});var s={};t.r(s),t.d(s,{default:()=>f});var i=t(89947),a=t(2706),o=t(96762),n=t(67619),u=t(56081),l=t(55591),d=t.n(l),g=t(83704),c=t(59338);async function p({token:e,database:r,additionalFields:t,additionalData:s,debug:i}){try{let a=await new Promise((r,t)=>{d().request({method:"GET",hostname:"www.googleapis.com",path:"/oauth2/v3/userinfo",headers:{Authorization:`Bearer ${e}`}},e=>{let t="";e.on("data",e=>{t+=e}),e.on("end",()=>{r(c.A.parse(t))})}).end()});if(!a?.email_verified)throw Error("No Google User.");let{given_name:o,family_name:n,email:u,sub:l,picture:p}=a,f={email:u,first_name:o,last_name:n,social_id:l,social_platform:"google",image:p,image_thumbnail:p,username:`google-user-${l}`};return s&&(f={...f,...s}),{...await (0,g.A)({database:r,email:u||"",payload:f,social_platform:"google",social_id:l,additionalFields:t,debug:i})}}catch(e){return console.log(`api-google-login.ts ERROR: ${e.message}`),{success:!1,payload:void 0,msg:e.message}}}async function f(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Failed!"});try{let{token:t,database:s,additionalFields:i,additionalData:a}=e.body,o=e.headers.authorization,n=(0,u.A)({key:o,database:s,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,msg:"Unauthorized"});let l=`datasquirel_user_${n.user_id}_${s}`,d=await p({database:l,token:t,additionalFields:i,additionalData:a});r.json(d)}catch(t){(0,n.A)({component:"/api/user/google-login/main-catch-error",message:t.message,user:{},req:e}),r.json({success:!1,msg:"Error: "+t.message})}}let m=(0,o.M)(s,"default"),_=(0,o.M)(s,"config"),h=new i.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/user/[user_id]/google-login",pathname:"/api/user/[user_id]/google-login",bundlePath:"",filename:""},userland:s})},56081:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(29021),i=t.n(s),a=t(95969);let o=({key:e,database:r,table:t,user_id:s,media:o})=>{if(!e||!s)return null;try{let n=process.env.DSQL_API_KEYS_PATH;if(!n)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let u=(0,a.A)({encryptedString:e}),l=JSON.parse(u||""),d=i().existsSync(`${n}/${l.sign}`);if(String(l.user_id)!==String(s)||!d)return null;if(!l.target_database||o)return l;if(!r&&l.target_database)return null;let g=l.target_database?.split(",").includes(String(r));if(g&&!l.target_table)return l;if(g&&!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}`),{error:`api-cred ERROR: ${e.message}`}}}},59338:(e,r,t)=>{t.d(r,{A:()=>s});let s={parse:function(e,r){if(e){if("object"==typeof e)return e;if("string"==typeof e)try{return JSON.parse(e,r)}catch(e){return}}},stringify:function(e,r,t){try{return JSON.stringify(e,r||void 0,t)}catch(e){return}}}}};var r=require("../../../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[2319,3704],()=>t(21748));module.exports=s})();