This commit is contained in:
Benjamin Toby
2024-11-06 12:13:31 +01:00
parent 19155164c5
commit 06ff13c653
240 changed files with 574 additions and 694 deletions
@@ -111,6 +111,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _functions_backend_social_login_handleSocialDb__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_social_login_handleSocialDb__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _shell_utils_camelJoinedtoCamelSpace__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2127);
/* harmony import */ var _shell_utils_camelJoinedtoCamelSpace__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_shell_utils_camelJoinedtoCamelSpace__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(1007);
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__);
// @ts-check
/**
* Imports
@@ -120,6 +122,7 @@ __webpack_require__.r(__webpack_exports__);
const githubLogin = __webpack_require__(6069);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* API handler
@@ -143,27 +146,16 @@ const githubLogin = __webpack_require__(6069);
* User auth
*
* @description Authenticate user
*/ const deletedKeys = fs.readFileSync("./apiKeys/deleted.txt", "utf8");
*/ const { code , email , clientId , clientSecret , database , additionalFields , } = req.body;
const authorization = req.headers.authorization || "";
if (deletedKeys.includes(authorization)) {
return res.json({
success: false,
msg: "Key Inactive!"
});
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default()({
key: authorization,
database
});
if (!apiCred?.user_id) {
throw new Error("Api Credentials invalid!");
}
const userJSON = _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_0___default()(authorization);
const user = userJSON ? JSON.parse(userJSON) : null;
const { user_id , full_access , csrf } = user;
try {
const decryptedCsrfJSON = _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_0___default()(csrf);
const decryptedCsrf = decryptedCsrfJSON ? JSON.parse(decryptedCsrfJSON) : null;
} catch (/** @type {any} */ error) {
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
component: "/api/user/google-login",
message: error.message
});
}
if (!full_access || !csrf) return res.json({
if (!apiCred.full_access || !apiCred.sign) return res.json({
success: false,
msg: "Unauthorized"
});
@@ -171,8 +163,7 @@ const githubLogin = __webpack_require__(6069);
* User auth
*
* @description Authenticate user
*/ const { code , email , clientId , clientSecret , database , additionalFields , } = req.body;
if (!code || !clientId || !clientSecret || !database) {
*/ if (!code || !clientId || !clientSecret || !database) {
return res.json({
success: false,
msg: "Missing query params"
@@ -199,7 +190,7 @@ const githubLogin = __webpack_require__(6069);
msg: "No github user returned"
});
}
const targetDbName = `datasquirel_user_${user_id}_${database}`;
const targetDbName = `datasquirel_user_${apiCred.user_id}_${database}`;
const socialId = gitHubUser.name || gitHubUser.id || gitHubUser.login;
const targetName = gitHubUser.name || gitHubUser.login;
const nameArray = targetName?.match(/ /) ? targetName?.split(" ") : targetName?.match(/\-/) ? targetName?.split("-") : [
@@ -236,15 +227,15 @@ const githubLogin = __webpack_require__(6069);
////////////////////////////////////////////////
res.json({
...loggedInGithubUser,
dsqlUserId: user_id
dsqlUserId: apiCred.user_id
});
////////////////////////////////////////
} catch (/** @type {any} */ error1) {
} catch (/** @type {any} */ error) {
////////////////////////////////////////
console.log("ERROR in 'github-auth' API route =>", error1.message);
console.log("ERROR in 'github-auth' API route =>", error.message);
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
component: "/api/social-login/github-auth/catch-error",
message: error1.message
message: error.message
});
res.json({
success: false,
@@ -267,7 +258,7 @@ const githubLogin = __webpack_require__(6069);
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__(7911)));
var __webpack_exports__ = __webpack_require__.X(0, [2224,2163,3017,3403,7547,5886,5338,8326,1311,1007,6926,7487,613,4294,6968,722,9971], () => (__webpack_exec__(7911)));
module.exports = __webpack_exports__;
})();