"use strict";(()=>{var e={};e.id=5770,e.ids=[5770],e.modules={47795:e=>{e.exports=require("generate-password")},27825:e=>{e.exports=require("lodash")},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")},81630:e=>{e.exports=require("http")},55591:e=>{e.exports=require("https")},33873:e=>{e.exports=require("path")},56891:(e,r,t)=>{t.r(r),t.d(r,{config:()=>m,default:()=>f,routeModule:()=>_});var s={};t.r(s),t.d(s,{default:()=>p});var a=t(89947),i=t(2706),o=t(96762),n=t(48225),u=t.n(n),l=t(77619),g=t.n(l),d=t(2853),c=t.n(d);async function p(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Failed!"});try{let{token:t,database:s,additionalFields:a}=e.body,i=e.headers.authorization,o=g()({key:i,database:s,user_id:String(e.query.user_id)});if(!o?.user_id)throw Error("Api Credentials invalid!");if(!o.full_access||!o.sign)return r.json({success:!1,msg:"Unauthorized"});let n=`datasquirel_user_${o.user_id}_${s}`,u=await c()({database:n,token:t,additionalFields:a});r.json(u)}catch(t){u()({component:"/api/user/google-login/main-catch-error",message:t.message,user:{},req:e}),r.json({success:!1,msg:"Error: "+t.message})}}let f=(0,o.M)(s,"default"),m=(0,o.M)(s,"config"),_=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/user/[user_id]/google-login",pathname:"/api/user/[user_id]/google-login",bundlePath:"",filename:""},userland:s})},2853:(e,r,t)=>{let s=t(55591),a=t(14385),i=t(27836);e.exports=async function({token:e,database:r,additionalFields:t}){try{let o=await new Promise((r,t)=>{s.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(i.parse(t))})}).end()});if(!o?.email_verified)throw Error("No Google User.");if(!r||"string"!=typeof r||r?.match(/ /))return{success:!1,user:void 0,msg:"Please provide a database slug(database name in lowercase with no spaces)"};let{given_name:n,family_name:u,email:l,sub:g,picture:d}=o,c={email:l,first_name:n,last_name:u,social_id:g,social_platform:"google",image:d,image_thumbnail:d,username:`google-user-${g}`};return{...await a({database:r,email:l||"",payload:c,social_platform:"google",social_id:g,additionalFields:t})}}catch(e){return console.log(`apo-google-login.js ERROR: ${e.message}`),{success:!1,user:void 0,msg:e.message}}}},77619:(e,r,t)=>{let s=t(29021),a=t(72835);e.exports=({key:e,database:r,table:t,user_id:i})=>{if(!e||!i)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 n=a({encryptedString:e}),u=JSON.parse(n||""),l=s.existsSync(`${o}/${u.sign}`);if(String(u.user_id)!==String(i)||!l)return null;if(!u.target_database)return u;if(!r&&u.target_database)return null;let g=u.target_database?.split(",").includes(String(r));if(g&&!u.target_table)return u;if(g&&!t&&u.target_table)return null;if(u.target_table?.split(",").includes(String(t)))return u;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),null}}},27836:e=>{e.exports={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,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,[4050,4385],()=>t(56891));module.exports=s})();