Files
dsql-admin/dsql-app/.local_dist/server/pages/api/social-login/github-auth.js
T
2024-12-06 14:24:26 +01:00

1 line
4.1 KiB
JavaScript

"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:()=>d,default:()=>m,routeModule:()=>g});var s={};r.r(s),r.d(s,{default:()=>h});var o=r(89947),i=r(2706),a=r(96762),n=r(14385),l=r.n(n),u=r(84930),c=r.n(u);let p=r(67684);async function h(e,t){if("GET"!==e.method)return t.json({msg:"Failed!"});let{code:r,email:s,invite:o}=e.query;try{let e=await p({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 i=await l()({email:e.email,payload:{email:e.email,first_name:c()(e.login)?.split(" ")[0],last_name:c()(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:o,res:t,social_id:e.id,supEmail:s?s.toString():void 0});t.json(i)}catch(e){console.log("ERROR in 'github-auth' API route =>",e.message),t.json({success:!1,msg:"Failed!"})}}let m=(0,a.M)(s,"default"),d=(0,a.M)(s,"config"),g=new o.PagesAPIRouteModule({definition:{kind:i.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),o=r(83634);e.exports=async function({code:e,clientId:t,clientSecret:r}){let i;try{let a=await o({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 i;let l=await o({method:"GET",hostname:"api.github.com",path:"/user",headers:{Authorization:`Bearer ${n.access_token}`,"User-Agent":"*"},scheme:"https"});if(i=JSON.parse(l),!i?.email&&i){let e=await s(`SELECT email FROM users WHERE social_login='1' AND social_platform='github' AND social_id='${i.id}'`);e&&e[0]&&(i.email=e[0].email)}}catch(e){console.log("ERROR in githubLogin.js backend function =>",e.message)}return i}},83634:(e,t,r)=>{let s=r(55591),o=r(81630),{URL:i}=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 i(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:o).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 o=0;o<r.length;o++){let i=r[o];if(0===i)continue;let a=i+1,n=r[o+1];s.push(`${t[i].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})();