"use strict";(()=>{var e={};e.id=7551,e.ids=[7551],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")},79551:e=>{e.exports=require("url")},13337:(e,t,r)=>{r.r(t),r.d(t,{config:()=>b,default:()=>_,routeModule:()=>q});var s={};r.r(s),r.d(s,{default:()=>f});var i=r(89947),o=r(2706),a=r(96762),n=r(20503),l=r.n(n),u=r(14385),c=r.n(u),p=r(84930),h=r.n(p),m=r(31341),d=r.n(m);let g=r(67684);async function f(e,t){if("GET"!==e.method)return t.json({msg:"Failed!"});let{code:r,email:s,invite:i}=e.query;try{let e=await g({code:r?.toString()||"",clientId:process.env.DSQL_GITHUB_ID||"",clientSecret:process.env.DSQL_GITHUB_SECRET||""});if(!e)return t.json({success:!1,msg:"No github user returned"});if(!e?.email&&!s)return t.json({success:!1,msg:"Github User Email not present"});let o=await c()({email:e.email,payload:{email:e.email,first_name:h()(e.login)?.split(" ")[0],last_name:h()(e.login)?.split(" ")[1],social_id:e.id,social_platform:"github",image:e.avatar_url,image_thumbnail:e.avatar_url,username:"github-user-"+e.name},social_platform:"github",invitation:i,social_id:e.id,supEmail:s?s.toString():void 0});if(o.payload?.csrf_k){let e=l()({data:JSON.stringify(o.payload)}),{keyCookieName:r,csrfCookieName:s}=d()();t.setHeader("Set-Cookie",[`${r}=${e};samesite=strict;path=/;HttpOnly=true;Secure=true`,`${s}=${o.payload.csrf_k};samesite=strict;path=/;HttpOnly=true`])}t.json(o)}catch(e){console.log("ERROR in 'github-auth' API route =>",e.message),t.json({success:!1,msg:"Failed!"})}}let _=(0,a.M)(s,"default"),b=(0,a.M)(s,"config"),q=new i.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/social-login/github-auth",pathname:"/api/social-login/github-auth",bundlePath:"",filename:""},userland:s})},67684:(e,t,r)=>{let s=r(51348),i=r(83634);e.exports=async function({code:e,clientId:t,clientSecret:r}){let o;try{let a=await i({method:"POST",hostname:"github.com",path:`/login/oauth/access_token?client_id=${t}&client_secret=${r}&code=${e}`,headers:{Accept:"application/json","User-Agent":"*"},scheme:"https"}),n=JSON.parse(a);if(!n?.access_token)return o;let l=await i({method:"GET",hostname:"api.github.com",path:"/user",headers:{Authorization:`Bearer ${n.access_token}`,"User-Agent":"*"},scheme:"https"});if(o=JSON.parse(l),!o?.email&&o){let e=await s(`SELECT email FROM users WHERE social_login='1' AND social_platform='github' AND social_id='${o.id}'`);e&&e[0]&&(o.email=e[0].email)}}catch(e){console.log("ERROR in githubLogin.js backend function =>",e.message)}return o}},83634:(e,t,r)=>{let s=r(55591),i=r(81630),{URL:o}=r(79551);e.exports=function({url:e,method:t,hostname:r,path:a,headers:n,body:l,port:u,scheme:c}){let p=l?JSON.stringify(l):null,h=e?new o(e):null,m={method:t||"GET",hostname:h?h.hostname:r,port:c?.match(/https/i)?443:h?h.protocol?.match(/https/i)?443:h.port:u?Number(u):80,headers:{}};return a&&(m.path=a),n&&(m.headers=n),l&&(m.headers["Content-Type"]="application/json",m.headers["Content-Length"]=p?Buffer.from(p).length:void 0),new Promise((e,t)=>{let r=(c?.match(/https/i)?s:h?.protocol?.match(/https/i)?s:i).request(m,r=>{var s="";r.on("data",function(e){s+=e}),r.on("end",function(){e(s)}),r.on("error",e=>{console.log("HTTP response error =>",e.message),t(`HTTP response error =>, ${e.message}`)}),r.on("close",()=>{console.log("HTTP(S) Response Closed Successfully")})});l&&r.write(p),r.on("error",e=>{console.log("HTTPS request ERROR =>",e.message),t(`HTTP request error =>, ${e.message}`)}),r.end()})}},84930:e=>{e.exports=function(e){if(!e?.match(/./))return"";if(e?.match(/ /))return e;if(!e)return null;{let t=e.split(""),r=[];for(let e=0;e<t.length;e++){let s=t[e];0!==e&&s.match(/[A-Z]/)&&r.push(e)}let s=[`${t[0].toUpperCase()}${e.substring(1,r[0])}`];for(let i=0;i<r.length;i++){let o=r[i];if(0===o)continue;let a=o+1,n=r[i+1];s.push(`${t[o].toUpperCase()}${e.substring(a,n)}`)}return s.join(" ")}}}};var t=require("../../../webpack-api-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[4050,4385],()=>r(13337));module.exports=s})();