This commit is contained in:
Benjamin Toby
2024-12-05 08:03:33 +01:00
parent 9686a22c96
commit 3ffd2d6777
821 changed files with 3251 additions and 91996 deletions
@@ -1,231 +1 @@
"use strict";
(() => {
var exports = {};
exports.id = 3115;
exports.ids = [3115];
exports.modules = {
/***/ 9538:
/***/ ((module) => {
module.exports = require("datasquirel");
/***/ }),
/***/ 3785:
/***/ ((module) => {
module.exports = require("generate-password");
/***/ }),
/***/ 6517:
/***/ ((module) => {
module.exports = require("lodash");
/***/ }),
/***/ 5184:
/***/ ((module) => {
module.exports = require("nodemailer");
/***/ }),
/***/ 6109:
/***/ ((module) => {
module.exports = require("sanitize-html");
/***/ }),
/***/ 2261:
/***/ ((module) => {
module.exports = require("serverless-mysql");
/***/ }),
/***/ 4300:
/***/ ((module) => {
module.exports = require("buffer");
/***/ }),
/***/ 6113:
/***/ ((module) => {
module.exports = require("crypto");
/***/ }),
/***/ 7147:
/***/ ((module) => {
module.exports = require("fs");
/***/ }),
/***/ 3685:
/***/ ((module) => {
module.exports = require("http");
/***/ }),
/***/ 5687:
/***/ ((module) => {
module.exports = require("https");
/***/ }),
/***/ 1017:
/***/ ((module) => {
module.exports = require("path");
/***/ }),
/***/ 7310:
/***/ ((module) => {
module.exports = require("url");
/***/ }),
/***/ 5389:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ handler)
/* harmony export */ });
/* harmony import */ var _functions_backend_social_login_handleSocialDb__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7839);
/* harmony import */ var _functions_backend_social_login_handleSocialDb__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_social_login_handleSocialDb__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _shell_utils_camelJoinedtoCamelSpace__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2127);
/* harmony import */ var _shell_utils_camelJoinedtoCamelSpace__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_shell_utils_camelJoinedtoCamelSpace__WEBPACK_IMPORTED_MODULE_1__);
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/ const githubLogin = __webpack_require__(6069);
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
/**
* API handler
* ==============================================================================
* @type {import("next").NextApiHandler}
*/ async function handler(req, res) {
/**
* Check method
*
* @description Check request method and return if invalid
*/ if (req.method !== "GET") return res.json({
msg: "Failed!"
});
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
/**
* User auth
*
* @description Authenticate user
*/ const { code , email , invite } = req.query;
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
/**
* Send Response
*
* @description Send a boolean response
*/ try {
/**
* Create new user folder and file
*
* @description Create new user folder and file
*/ const gitHubUser = await githubLogin({
code: code?.toString() || "",
clientId: process.env.DSQL_GITHUB_ID || "",
clientSecret: process.env.DSQL_GITHUB_SECRET || ""
});
if (!gitHubUser) {
return res.json({
success: false,
msg: "No github user returned"
});
}
if (!gitHubUser?.email && !email) {
return res.json({
success: false,
msg: "Github User Email not present"
});
}
const loggedInGithubUser = await _functions_backend_social_login_handleSocialDb__WEBPACK_IMPORTED_MODULE_0___default()({
email: gitHubUser.email,
payload: {
email: gitHubUser.email,
first_name: _shell_utils_camelJoinedtoCamelSpace__WEBPACK_IMPORTED_MODULE_1___default()(gitHubUser.login)?.split(" ")[0],
last_name: _shell_utils_camelJoinedtoCamelSpace__WEBPACK_IMPORTED_MODULE_1___default()(gitHubUser.login)?.split(" ")[1],
social_id: gitHubUser.id,
social_platform: "github",
image: gitHubUser.avatar_url,
image_thumbnail: gitHubUser.avatar_url,
username: "github-user-" + gitHubUser.name
},
social_platform: "github",
invitation: invite,
res: res,
social_id: gitHubUser.id,
supEmail: email ? email.toString() : undefined
});
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
res.json(loggedInGithubUser);
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
} catch (/** @type {any} */ error) {
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
console.log("ERROR in 'github-auth' API route =>", error.message);
// serverError({
// component: "/api/social-login/github-auth/catch-error",
// message: error.message,
// user: user,
// });
res.json({
success: false,
msg: "Failed!"
});
////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
}
}
/***/ })
};
;
// load runtime
var __webpack_require__ = require("../../../webpack-api-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = __webpack_require__.X(0, [2224,2163,3017,3403,7547,5886,5338,8326,1311,6926,7487,613,4294,6968,722,9971], () => (__webpack_exec__(5389)));
module.exports = __webpack_exports__;
})();
"use strict";(()=>{var e={};e.id=7551,e.ids=[7551],e.modules={28187:e=>{e.exports=require("@moduletrace/datasquirel")},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(36946),l=r.n(n),u=r(17549),c=r.n(u);let p=r(59777);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})},10779:(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()})}},59777:(e,t,r)=>{r(29021);let{hashPassword:s}=r(18481);r(77538);let o=r(10779),i=r(51348);e.exports=async function({code:e,clientId:t,clientSecret:r}){let s;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 s;let l=await o({method:"GET",hostname:"api.github.com",path:"/user",headers:{Authorization:`Bearer ${n.access_token}`,"User-Agent":"*"},scheme:"https"});if(s=JSON.parse(l),!s?.email&&s){let e=await i(`SELECT email FROM users WHERE social_login='1' AND social_platform='github' AND social_id='${s.id}'`);e&&e[0]&&(s.email=e[0].email)}}catch(e){console.log("ERROR in githubLogin.js backend function =>",e.message)}return s}},18481:(e,t,r)=>{let{createHmac:s}=r(55511);t.hashPassword=function(e){let t=s("sha512",process.env.DSQL_ENCRYPTION_PASSWORD||"");return t.update(e),t.digest("base64")}},17549: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,6946],()=>r(13337));module.exports=s})();