From 3695a759197a2b7164e6b6d8928e36a7e01753fb Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Mon, 20 Jan 2025 08:26:15 +0100 Subject: [PATCH] Updates --- .../api/social-login/handleSocialDb.d.ts | 2 +- .../api/social-login/handleSocialDb.js | 26 ++++++++++-- .../api/social-login/loginSocialUser.d.ts | 3 +- .../api/social-login/loginSocialUser.js | 3 +- .../api/users/social/api-google-login.d.ts | 2 +- .../api/users/social/api-google-login.js | 3 +- dist/package-shared/types/index.d.ts | 2 + dist/users/social/google-auth.d.ts | 3 +- dist/users/social/google-auth.js | 3 +- .../api/social-login/handleSocialDb.ts | 41 ++++++++++++++++++- .../api/social-login/loginSocialUser.ts | 3 ++ .../api/users/social/api-google-login.ts | 2 + package-shared/types/index.ts | 2 + package.json | 2 +- users/social/google-auth.ts | 3 ++ 15 files changed, 87 insertions(+), 13 deletions(-) diff --git a/dist/package-shared/functions/api/social-login/handleSocialDb.d.ts b/dist/package-shared/functions/api/social-login/handleSocialDb.d.ts index 91061df..c59c800 100644 --- a/dist/package-shared/functions/api/social-login/handleSocialDb.d.ts +++ b/dist/package-shared/functions/api/social-login/handleSocialDb.d.ts @@ -2,4 +2,4 @@ import { APILoginFunctionReturn, HandleSocialDbFunctionParams } from "../../../t /** * # Handle Social DB */ -export default function handleSocialDb({ database, social_id, email, social_platform, payload, invitation, supEmail, additionalFields, useLocal, }: HandleSocialDbFunctionParams): Promise; +export default function handleSocialDb({ database, social_id, email, social_platform, payload, invitation, supEmail, additionalFields, useLocal, debug, }: HandleSocialDbFunctionParams): Promise; diff --git a/dist/package-shared/functions/api/social-login/handleSocialDb.js b/dist/package-shared/functions/api/social-login/handleSocialDb.js index f74977e..330e3c1 100644 --- a/dist/package-shared/functions/api/social-login/handleSocialDb.js +++ b/dist/package-shared/functions/api/social-login/handleSocialDb.js @@ -25,22 +25,30 @@ const loginSocialUser_1 = __importDefault(require("./loginSocialUser")); * # Handle Social DB */ function handleSocialDb(_a) { - return __awaiter(this, arguments, void 0, function* ({ database, social_id, email, social_platform, payload, invitation, supEmail, additionalFields, useLocal, }) { + return __awaiter(this, arguments, void 0, function* ({ database, social_id, email, social_platform, payload, invitation, supEmail, additionalFields, useLocal, debug, }) { try { const finalDbName = database ? database : "datasquirel"; - const dbAppend = database ? `${finalDbName}.` : ""; + const dbAppend = useLocal ? "" : `${finalDbName}.`; const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `; const existingSocialIdUserValues = [ social_id.toString(), social_platform, ]; + if (debug) { + console.log("handleSocialDb:existingSocialIdUserQuery", existingSocialIdUserQuery); + console.log("handleSocialDb:existingSocialIdUserValues", existingSocialIdUserValues); + } let existingSocialIdUser = yield (0, varDatabaseDbHandler_1.default)({ database: database ? database : "datasquirel", queryString: existingSocialIdUserQuery, queryValuesArray: existingSocialIdUserValues, useLocal, + debug, }); - if (existingSocialIdUser && existingSocialIdUser[0]) { + if (debug) { + console.log("handleSocialDb:existingSocialIdUser", existingSocialIdUser); + } + if (existingSocialIdUser === null || existingSocialIdUser === void 0 ? void 0 : existingSocialIdUser[0]) { return yield (0, loginSocialUser_1.default)({ user: existingSocialIdUser[0], social_platform, @@ -48,6 +56,7 @@ function handleSocialDb(_a) { database, additionalFields, useLocal, + debug, }); } const finalEmail = email ? email : supEmail ? supEmail : null; @@ -59,11 +68,18 @@ function handleSocialDb(_a) { }; } const existingEmailOnlyQuery = `SELECT * FROM ${dbAppend}users WHERE email='${finalEmail}'`; + if (debug) { + console.log("handleSocialDb:existingEmailOnlyQuery", existingEmailOnlyQuery); + } let existingEmailOnly = yield (0, varDatabaseDbHandler_1.default)({ database: database ? database : "datasquirel", queryString: existingEmailOnlyQuery, useLocal, + debug, }); + if (debug) { + console.log("handleSocialDb:existingEmailOnly", existingEmailOnly); + } if (existingEmailOnly && existingEmailOnly[0]) { return { success: false, @@ -78,6 +94,7 @@ function handleSocialDb(_a) { queryString: foundUserQuery, queryValuesArray: foundUserQueryValues, useLocal, + debug, }); if (foundUser && foundUser[0]) { return yield (0, loginSocialUser_1.default)({ @@ -87,6 +104,7 @@ function handleSocialDb(_a) { database, additionalFields, useLocal, + debug, }); } const socialHashedPassword = (0, encrypt_1.default)({ @@ -122,6 +140,7 @@ function handleSocialDb(_a) { database: database ? database : "datasquirel", queryString: newUserQueriedQuery, useLocal, + debug, }); if (!newUserQueried || !newUserQueried[0]) return { @@ -180,6 +199,7 @@ function handleSocialDb(_a) { database, additionalFields, useLocal, + debug, }); } else { diff --git a/dist/package-shared/functions/api/social-login/loginSocialUser.d.ts b/dist/package-shared/functions/api/social-login/loginSocialUser.d.ts index a024f35..df385db 100644 --- a/dist/package-shared/functions/api/social-login/loginSocialUser.d.ts +++ b/dist/package-shared/functions/api/social-login/loginSocialUser.d.ts @@ -11,6 +11,7 @@ type Param = { database?: string; additionalFields?: string[]; useLocal?: boolean; + debug?: boolean; }; /** * Function to login social user @@ -18,5 +19,5 @@ type Param = { * @description This function logs in the user after 'handleSocialDb' function finishes * the user creation or confirmation process */ -export default function loginSocialUser({ user, social_platform, invitation, database, additionalFields, useLocal, }: Param): Promise; +export default function loginSocialUser({ user, social_platform, invitation, database, additionalFields, useLocal, debug, }: Param): Promise; export {}; diff --git a/dist/package-shared/functions/api/social-login/loginSocialUser.js b/dist/package-shared/functions/api/social-login/loginSocialUser.js index ab27ef8..c285bab 100644 --- a/dist/package-shared/functions/api/social-login/loginSocialUser.js +++ b/dist/package-shared/functions/api/social-login/loginSocialUser.js @@ -22,7 +22,7 @@ const varDatabaseDbHandler_1 = __importDefault(require("../../backend/varDatabas * the user creation or confirmation process */ function loginSocialUser(_a) { - return __awaiter(this, arguments, void 0, function* ({ user, social_platform, invitation, database, additionalFields, useLocal, }) { + return __awaiter(this, arguments, void 0, function* ({ user, social_platform, invitation, database, additionalFields, useLocal, debug, }) { const finalDbName = database ? database : "datasquirel"; const dbAppend = database ? `\`${finalDbName}\`.` : ""; const foundUserQuery = `SELECT * FROM ${dbAppend}\`users\` WHERE email=? AND social_id=? AND social_platform=?`; @@ -32,6 +32,7 @@ function loginSocialUser(_a) { queryString: foundUserQuery, queryValuesArray: foundUserValues, useLocal, + debug, }); if (!(foundUser === null || foundUser === void 0 ? void 0 : foundUser[0])) return { diff --git a/dist/package-shared/functions/api/users/social/api-google-login.d.ts b/dist/package-shared/functions/api/users/social/api-google-login.d.ts index 996e949..145fb07 100644 --- a/dist/package-shared/functions/api/users/social/api-google-login.d.ts +++ b/dist/package-shared/functions/api/users/social/api-google-login.d.ts @@ -2,4 +2,4 @@ import { APIGoogleLoginFunctionParams, APILoginFunctionReturn } from "../../../. /** * # API google login */ -export default function apiGoogleLogin({ token, database, additionalFields, additionalData, }: APIGoogleLoginFunctionParams): Promise; +export default function apiGoogleLogin({ token, database, additionalFields, additionalData, debug, }: APIGoogleLoginFunctionParams): Promise; diff --git a/dist/package-shared/functions/api/users/social/api-google-login.js b/dist/package-shared/functions/api/users/social/api-google-login.js index 66b097b..7e7d5b2 100644 --- a/dist/package-shared/functions/api/users/social/api-google-login.js +++ b/dist/package-shared/functions/api/users/social/api-google-login.js @@ -20,7 +20,7 @@ const ejson_1 = __importDefault(require("../../../../utils/ejson")); * # API google login */ function apiGoogleLogin(_a) { - return __awaiter(this, arguments, void 0, function* ({ token, database, additionalFields, additionalData, }) { + return __awaiter(this, arguments, void 0, function* ({ token, database, additionalFields, additionalData, debug, }) { try { const gUser = yield new Promise((resolve, reject) => { https_1.default @@ -80,6 +80,7 @@ function apiGoogleLogin(_a) { social_platform: "google", social_id: sub, additionalFields, + debug, }); //////////////////////////////////////// //////////////////////////////////////// diff --git a/dist/package-shared/types/index.d.ts b/dist/package-shared/types/index.d.ts index f187e95..5031329 100644 --- a/dist/package-shared/types/index.d.ts +++ b/dist/package-shared/types/index.d.ts @@ -1073,6 +1073,7 @@ export type APIGoogleLoginFunctionParams = { additionalData?: { [key: string]: string | number; }; + debug?: boolean; }; export type APIGoogleLoginFunction = (params: APIGoogleLoginFunctionParams) => Promise; /** @@ -1088,6 +1089,7 @@ export type HandleSocialDbFunctionParams = { supEmail?: string; additionalFields?: string[]; useLocal?: boolean; + debug?: boolean; }; export type HandleSocialDbFunctionReturn = { success: boolean; diff --git a/dist/users/social/google-auth.d.ts b/dist/users/social/google-auth.d.ts index 528a180..dad08f4 100644 --- a/dist/users/social/google-auth.d.ts +++ b/dist/users/social/google-auth.d.ts @@ -13,9 +13,10 @@ type Param = { }; apiUserID?: string | number; useLocal?: boolean; + debug?: boolean; }; /** * # SERVER FUNCTION: Login with google Function */ -export default function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, }: Param): Promise; +export default function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, debug, }: Param): Promise; export {}; diff --git a/dist/users/social/google-auth.js b/dist/users/social/google-auth.js index efff29e..daede78 100644 --- a/dist/users/social/google-auth.js +++ b/dist/users/social/google-auth.js @@ -22,7 +22,7 @@ const write_auth_files_1 = require("../../package-shared/functions/backend/auth/ * # SERVER FUNCTION: Login with google Function */ function googleAuth(_a) { - return __awaiter(this, arguments, void 0, function* ({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, }) { + return __awaiter(this, arguments, void 0, function* ({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, debug, }) { var _b; const grabedHostNames = (0, grab_host_names_1.default)(); const { host, port, scheme } = grabedHostNames; @@ -78,6 +78,7 @@ function googleAuth(_a) { additionalFields, database: DSQL_DB_NAME, additionalData, + debug, }); } else { diff --git a/package-shared/functions/api/social-login/handleSocialDb.ts b/package-shared/functions/api/social-login/handleSocialDb.ts index 031bd7b..8a8c828 100644 --- a/package-shared/functions/api/social-login/handleSocialDb.ts +++ b/package-shared/functions/api/social-login/handleSocialDb.ts @@ -24,10 +24,11 @@ export default async function handleSocialDb({ supEmail, additionalFields, useLocal, + debug, }: HandleSocialDbFunctionParams): Promise { try { const finalDbName = database ? database : "datasquirel"; - const dbAppend = database ? `${finalDbName}.` : ""; + const dbAppend = useLocal ? "" : `${finalDbName}.`; const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `; const existingSocialIdUserValues = [ @@ -35,14 +36,33 @@ export default async function handleSocialDb({ social_platform, ]; + if (debug) { + console.log( + "handleSocialDb:existingSocialIdUserQuery", + existingSocialIdUserQuery + ); + console.log( + "handleSocialDb:existingSocialIdUserValues", + existingSocialIdUserValues + ); + } + let existingSocialIdUser = await varDatabaseDbHandler({ database: database ? database : "datasquirel", queryString: existingSocialIdUserQuery, queryValuesArray: existingSocialIdUserValues, useLocal, + debug, }); - if (existingSocialIdUser && existingSocialIdUser[0]) { + if (debug) { + console.log( + "handleSocialDb:existingSocialIdUser", + existingSocialIdUser + ); + } + + if (existingSocialIdUser?.[0]) { return await loginSocialUser({ user: existingSocialIdUser[0], social_platform, @@ -50,6 +70,7 @@ export default async function handleSocialDb({ database, additionalFields, useLocal, + debug, }); } @@ -65,12 +86,24 @@ export default async function handleSocialDb({ const existingEmailOnlyQuery = `SELECT * FROM ${dbAppend}users WHERE email='${finalEmail}'`; + if (debug) { + console.log( + "handleSocialDb:existingEmailOnlyQuery", + existingEmailOnlyQuery + ); + } + let existingEmailOnly = await varDatabaseDbHandler({ database: database ? database : "datasquirel", queryString: existingEmailOnlyQuery, useLocal, + debug, }); + if (debug) { + console.log("handleSocialDb:existingEmailOnly", existingEmailOnly); + } + if (existingEmailOnly && existingEmailOnly[0]) { return { success: false, @@ -87,6 +120,7 @@ export default async function handleSocialDb({ queryString: foundUserQuery, queryValuesArray: foundUserQueryValues, useLocal, + debug, }); if (foundUser && foundUser[0]) { @@ -97,6 +131,7 @@ export default async function handleSocialDb({ database, additionalFields, useLocal, + debug, }); } @@ -142,6 +177,7 @@ export default async function handleSocialDb({ database: database ? database : "datasquirel", queryString: newUserQueriedQuery, useLocal, + debug, }); if (!newUserQueried || !newUserQueried[0]) @@ -220,6 +256,7 @@ export default async function handleSocialDb({ database, additionalFields, useLocal, + debug, }); } else { console.log( diff --git a/package-shared/functions/api/social-login/loginSocialUser.ts b/package-shared/functions/api/social-login/loginSocialUser.ts index fcc8170..65eb7ba 100644 --- a/package-shared/functions/api/social-login/loginSocialUser.ts +++ b/package-shared/functions/api/social-login/loginSocialUser.ts @@ -17,6 +17,7 @@ type Param = { database?: string; additionalFields?: string[]; useLocal?: boolean; + debug?: boolean; }; /** @@ -32,6 +33,7 @@ export default async function loginSocialUser({ database, additionalFields, useLocal, + debug, }: Param): Promise { const finalDbName = database ? database : "datasquirel"; const dbAppend = database ? `\`${finalDbName}\`.` : ""; @@ -44,6 +46,7 @@ export default async function loginSocialUser({ queryString: foundUserQuery, queryValuesArray: foundUserValues, useLocal, + debug, }); if (!foundUser?.[0]) diff --git a/package-shared/functions/api/users/social/api-google-login.ts b/package-shared/functions/api/users/social/api-google-login.ts index 68f52f4..9bb40dd 100644 --- a/package-shared/functions/api/users/social/api-google-login.ts +++ b/package-shared/functions/api/users/social/api-google-login.ts @@ -15,6 +15,7 @@ export default async function apiGoogleLogin({ database, additionalFields, additionalData, + debug, }: APIGoogleLoginFunctionParams): Promise { try { const gUser: GoogleOauth2User | undefined = await new Promise( @@ -87,6 +88,7 @@ export default async function apiGoogleLogin({ social_platform: "google", social_id: sub, additionalFields, + debug, }); //////////////////////////////////////// diff --git a/package-shared/types/index.ts b/package-shared/types/index.ts index 745a64a..4335c53 100644 --- a/package-shared/types/index.ts +++ b/package-shared/types/index.ts @@ -1257,6 +1257,7 @@ export type APIGoogleLoginFunctionParams = { database: string; additionalFields?: string[]; additionalData?: { [key: string]: string | number }; + debug?: boolean; }; export type APIGoogleLoginFunction = ( @@ -1276,6 +1277,7 @@ export type HandleSocialDbFunctionParams = { supEmail?: string; additionalFields?: string[]; useLocal?: boolean; + debug?: boolean; }; export type HandleSocialDbFunctionReturn = { diff --git a/package.json b/package.json index 9720604..2c5a41b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "3.7.5", + "version": "3.7.6", "description": "Cloud-based SQL data management tool", "main": "dist/index.js", "bin": { diff --git a/users/social/google-auth.ts b/users/social/google-auth.ts index 412a4e8..e1d589a 100644 --- a/users/social/google-auth.ts +++ b/users/social/google-auth.ts @@ -17,6 +17,7 @@ type Param = { additionalData?: { [s: string]: string | number }; apiUserID?: string | number; useLocal?: boolean; + debug?: boolean; }; /** @@ -33,6 +34,7 @@ export default async function googleAuth({ additionalData, apiUserID, useLocal, + debug, }: Param): Promise { const grabedHostNames = grabHostNames(); const { host, port, scheme } = grabedHostNames; @@ -101,6 +103,7 @@ export default async function googleAuth({ additionalFields, database: DSQL_DB_NAME, additionalData, + debug, }); } else { /**