From c210e6ca4670b56e9d7e5282522993d6c4b0797d Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Mon, 20 Jan 2025 08:42:35 +0100 Subject: [PATCH] Updates --- .../api/social-login/handleSocialDb.js | 26 +++++++++++-------- .../api/users/social/api-google-login.js | 10 ------- .../functions/backend/varDatabaseDbHandler.js | 1 + dist/package-shared/types/index.d.ts | 2 +- .../utils/db/conn-db-handler.js | 1 + dist/users/social/google-auth.js | 4 ++- .../api/social-login/handleSocialDb.ts | 26 +++++++++++-------- .../api/users/social/api-google-login.ts | 12 --------- .../functions/backend/varDatabaseDbHandler.ts | 1 + package-shared/types/index.ts | 2 +- package-shared/utils/db/conn-db-handler.ts | 1 + package.json | 2 +- users/social/google-auth.ts | 5 +++- 13 files changed, 44 insertions(+), 49 deletions(-) diff --git a/dist/package-shared/functions/api/social-login/handleSocialDb.js b/dist/package-shared/functions/api/social-login/handleSocialDb.js index 330e3c1..8319685 100644 --- a/dist/package-shared/functions/api/social-login/handleSocialDb.js +++ b/dist/package-shared/functions/api/social-login/handleSocialDb.js @@ -27,7 +27,11 @@ const loginSocialUser_1 = __importDefault(require("./loginSocialUser")); function handleSocialDb(_a) { 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 finalDbName = useLocal + ? undefined + : database + ? database + : "datasquirel"; const dbAppend = useLocal ? "" : `${finalDbName}.`; const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `; const existingSocialIdUserValues = [ @@ -39,7 +43,7 @@ function handleSocialDb(_a) { console.log("handleSocialDb:existingSocialIdUserValues", existingSocialIdUserValues); } let existingSocialIdUser = yield (0, varDatabaseDbHandler_1.default)({ - database: database ? database : "datasquirel", + database: finalDbName, queryString: existingSocialIdUserQuery, queryValuesArray: existingSocialIdUserValues, useLocal, @@ -53,7 +57,7 @@ function handleSocialDb(_a) { user: existingSocialIdUser[0], social_platform, invitation, - database, + database: finalDbName, additionalFields, useLocal, debug, @@ -72,7 +76,7 @@ function handleSocialDb(_a) { console.log("handleSocialDb:existingEmailOnlyQuery", existingEmailOnlyQuery); } let existingEmailOnly = yield (0, varDatabaseDbHandler_1.default)({ - database: database ? database : "datasquirel", + database: finalDbName, queryString: existingEmailOnlyQuery, useLocal, debug, @@ -90,7 +94,7 @@ function handleSocialDb(_a) { const foundUserQuery = `SELECT * FROM ${dbAppend}users WHERE email=? AND social_login='1' AND social_platform=? AND social_id=?`; const foundUserQueryValues = [finalEmail, social_platform, social_id]; const foundUser = yield (0, varDatabaseDbHandler_1.default)({ - database: database ? database : "datasquirel", + database: finalDbName, queryString: foundUserQuery, queryValuesArray: foundUserQueryValues, useLocal, @@ -101,7 +105,7 @@ function handleSocialDb(_a) { user: payload, social_platform, invitation, - database, + database: finalDbName, additionalFields, useLocal, debug, @@ -119,9 +123,9 @@ function handleSocialDb(_a) { data[key] = payload[key]; }); const newUser = yield (0, addDbEntry_1.default)({ - dbContext: database ? "Dsql User" : undefined, - paradigm: database ? "Full Access" : undefined, - dbFullName: database ? database : "datasquirel", + dbContext: finalDbName ? "Dsql User" : undefined, + paradigm: finalDbName ? "Full Access" : undefined, + dbFullName: finalDbName, tableName: "users", duplicateColumnName: "email", duplicateColumnValue: finalEmail, @@ -137,7 +141,7 @@ function handleSocialDb(_a) { } const newUserQueriedQuery = `SELECT * FROM ${dbAppend}users WHERE id='${newUser.insertId}'`; const newUserQueried = yield (0, varDatabaseDbHandler_1.default)({ - database: database ? database : "datasquirel", + database: finalDbName, queryString: newUserQueriedQuery, useLocal, debug, @@ -196,7 +200,7 @@ function handleSocialDb(_a) { user: newUserQueried[0], social_platform, invitation, - database, + database: finalDbName, additionalFields, useLocal, debug, 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 7e7d5b2..1c610f7 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 @@ -44,16 +44,6 @@ function apiGoogleLogin(_a) { }); if (!(gUser === null || gUser === void 0 ? void 0 : gUser.email_verified)) throw new Error("No Google User."); - //////////////////////////////////////// - //////////////////////////////////////// - //////////////////////////////////////// - if (!database || typeof database != "string" || (database === null || database === void 0 ? void 0 : database.match(/ /))) { - return { - success: false, - payload: undefined, - msg: "Please provide a database slug(database name in lowercase with no spaces)", - }; - } /** * Create new user folder and file * diff --git a/dist/package-shared/functions/backend/varDatabaseDbHandler.js b/dist/package-shared/functions/backend/varDatabaseDbHandler.js index c778956..ae44fc2 100644 --- a/dist/package-shared/functions/backend/varDatabaseDbHandler.js +++ b/dist/package-shared/functions/backend/varDatabaseDbHandler.js @@ -30,6 +30,7 @@ function varDatabaseDbHandler(_a) { if (debug) { console.log(`varDatabaseDbHandler:query:`, queryString); console.log(`varDatabaseDbHandler:values:`, queryValuesArray); + console.log(`varDatabaseDbHandler:CONNECTION:`, CONNECTION.getConfig()); } let results = yield (0, conn_db_handler_1.default)(CONNECTION, queryString, queryValuesArray); if (debug) { diff --git a/dist/package-shared/types/index.d.ts b/dist/package-shared/types/index.d.ts index 5031329..dfb66c5 100644 --- a/dist/package-shared/types/index.d.ts +++ b/dist/package-shared/types/index.d.ts @@ -1068,7 +1068,7 @@ export type APIGetUserFunctionParams = { */ export type APIGoogleLoginFunctionParams = { token: string; - database: string; + database?: string; additionalFields?: string[]; additionalData?: { [key: string]: string | number; diff --git a/dist/package-shared/utils/db/conn-db-handler.js b/dist/package-shared/utils/db/conn-db-handler.js index 34fde60..49e3880 100644 --- a/dist/package-shared/utils/db/conn-db-handler.js +++ b/dist/package-shared/utils/db/conn-db-handler.js @@ -59,6 +59,7 @@ values) { } catch (error) { console.log(`connDbHandler Error: ${error.message}`); + console.log(conn === null || conn === void 0 ? void 0 : conn.getConfig()); return null; } finally { diff --git a/dist/users/social/google-auth.js b/dist/users/social/google-auth.js index daede78..1e93611 100644 --- a/dist/users/social/google-auth.js +++ b/dist/users/social/google-auth.js @@ -73,10 +73,12 @@ function googleAuth(_a) { (DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) && (DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) && useLocal) { + if (debug) { + console.log(`Google login with Local Paradigm ...`); + } httpResponse = yield (0, api_google_login_1.default)({ token, additionalFields, - database: DSQL_DB_NAME, additionalData, debug, }); diff --git a/package-shared/functions/api/social-login/handleSocialDb.ts b/package-shared/functions/api/social-login/handleSocialDb.ts index 8a8c828..e611a73 100644 --- a/package-shared/functions/api/social-login/handleSocialDb.ts +++ b/package-shared/functions/api/social-login/handleSocialDb.ts @@ -27,7 +27,11 @@ export default async function handleSocialDb({ debug, }: HandleSocialDbFunctionParams): Promise { try { - const finalDbName = database ? database : "datasquirel"; + const finalDbName = useLocal + ? undefined + : database + ? database + : "datasquirel"; const dbAppend = useLocal ? "" : `${finalDbName}.`; const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `; @@ -48,7 +52,7 @@ export default async function handleSocialDb({ } let existingSocialIdUser = await varDatabaseDbHandler({ - database: database ? database : "datasquirel", + database: finalDbName, queryString: existingSocialIdUserQuery, queryValuesArray: existingSocialIdUserValues, useLocal, @@ -67,7 +71,7 @@ export default async function handleSocialDb({ user: existingSocialIdUser[0], social_platform, invitation, - database, + database: finalDbName, additionalFields, useLocal, debug, @@ -94,7 +98,7 @@ export default async function handleSocialDb({ } let existingEmailOnly = await varDatabaseDbHandler({ - database: database ? database : "datasquirel", + database: finalDbName, queryString: existingEmailOnlyQuery, useLocal, debug, @@ -116,7 +120,7 @@ export default async function handleSocialDb({ const foundUserQueryValues = [finalEmail, social_platform, social_id]; const foundUser = await varDatabaseDbHandler({ - database: database ? database : "datasquirel", + database: finalDbName, queryString: foundUserQuery, queryValuesArray: foundUserQueryValues, useLocal, @@ -128,7 +132,7 @@ export default async function handleSocialDb({ user: payload, social_platform, invitation, - database, + database: finalDbName, additionalFields, useLocal, debug, @@ -150,9 +154,9 @@ export default async function handleSocialDb({ }); const newUser = await addDbEntry({ - dbContext: database ? "Dsql User" : undefined, - paradigm: database ? "Full Access" : undefined, - dbFullName: database ? database : "datasquirel", + dbContext: finalDbName ? "Dsql User" : undefined, + paradigm: finalDbName ? "Full Access" : undefined, + dbFullName: finalDbName, tableName: "users", duplicateColumnName: "email", duplicateColumnValue: finalEmail, @@ -174,7 +178,7 @@ export default async function handleSocialDb({ const newUserQueriedQuery = `SELECT * FROM ${dbAppend}users WHERE id='${newUser.insertId}'`; const newUserQueried = await varDatabaseDbHandler({ - database: database ? database : "datasquirel", + database: finalDbName, queryString: newUserQueriedQuery, useLocal, debug, @@ -253,7 +257,7 @@ export default async function handleSocialDb({ user: newUserQueried[0], social_platform, invitation, - database, + database: finalDbName, additionalFields, useLocal, debug, 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 9bb40dd..2052e22 100644 --- a/package-shared/functions/api/users/social/api-google-login.ts +++ b/package-shared/functions/api/users/social/api-google-login.ts @@ -46,18 +46,6 @@ export default async function apiGoogleLogin({ if (!gUser?.email_verified) throw new Error("No Google User."); - //////////////////////////////////////// - //////////////////////////////////////// - //////////////////////////////////////// - - if (!database || typeof database != "string" || database?.match(/ /)) { - return { - success: false, - payload: undefined, - msg: "Please provide a database slug(database name in lowercase with no spaces)", - }; - } - /** * Create new user folder and file * diff --git a/package-shared/functions/backend/varDatabaseDbHandler.ts b/package-shared/functions/backend/varDatabaseDbHandler.ts index a30534d..f79d355 100644 --- a/package-shared/functions/backend/varDatabaseDbHandler.ts +++ b/package-shared/functions/backend/varDatabaseDbHandler.ts @@ -30,6 +30,7 @@ export default async function varDatabaseDbHandler({ if (debug) { console.log(`varDatabaseDbHandler:query:`, queryString); console.log(`varDatabaseDbHandler:values:`, queryValuesArray); + console.log(`varDatabaseDbHandler:CONNECTION:`, CONNECTION.getConfig()); } let results = await connDbHandler( diff --git a/package-shared/types/index.ts b/package-shared/types/index.ts index 4335c53..c117600 100644 --- a/package-shared/types/index.ts +++ b/package-shared/types/index.ts @@ -1254,7 +1254,7 @@ export type APIGetUserFunctionParams = { */ export type APIGoogleLoginFunctionParams = { token: string; - database: string; + database?: string; additionalFields?: string[]; additionalData?: { [key: string]: string | number }; debug?: boolean; diff --git a/package-shared/utils/db/conn-db-handler.ts b/package-shared/utils/db/conn-db-handler.ts index 1d9d8ff..1396fb7 100644 --- a/package-shared/utils/db/conn-db-handler.ts +++ b/package-shared/utils/db/conn-db-handler.ts @@ -56,6 +56,7 @@ export default async function connDbHandler( } } catch (error: any) { console.log(`connDbHandler Error: ${error.message}`); + console.log(conn?.getConfig()); return null; } finally { conn?.end(); diff --git a/package.json b/package.json index 2c5a41b..ea3bc85 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "3.7.6", + "version": "3.7.7", "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 e1d589a..a78334a 100644 --- a/users/social/google-auth.ts +++ b/users/social/google-auth.ts @@ -98,10 +98,13 @@ export default async function googleAuth({ DSQL_DB_NAME?.match(/./) && useLocal ) { + if (debug) { + console.log(`Google login with Local Paradigm ...`); + } + httpResponse = await apiGoogleLogin({ token, additionalFields, - database: DSQL_DB_NAME, additionalData, debug, });