From cd4a2f7902f0626978e3d1317709ad963e2665e5 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Sun, 4 May 2025 21:13:21 +0100 Subject: [PATCH] Updates --- .../api/social-login/handleSocialDb.d.ts | 2 +- .../api/social-login/handleSocialDb.js | 52 ++++++---------- .../api/users/social/api-github-login.js | 1 - .../api/users/social/api-google-login.js | 1 - dist/package-shared/types/index.d.ts | 1 - .../api/social-login/handleSocialDb.ts | 61 +++++++------------ .../api/users/social/api-github-login.ts | 1 - .../api/users/social/api-google-login.ts | 1 - package-shared/types/index.ts | 1 - package.json | 2 +- 10 files changed, 42 insertions(+), 81 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 6827794..07adb30 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, debug, loginOnly, }: HandleSocialDbFunctionParams): Promise; +export default function handleSocialDb({ database, email, social_platform, payload, invitation, supEmail, additionalFields, debug, loginOnly, }: 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 94f5b63..278d289 100644 --- a/dist/package-shared/functions/api/social-login/handleSocialDb.js +++ b/dist/package-shared/functions/api/social-login/handleSocialDb.js @@ -25,7 +25,7 @@ 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, debug, loginOnly, }) { + return __awaiter(this, arguments, void 0, function* ({ database, email, social_platform, payload, invitation, supEmail, additionalFields, debug, loginOnly, }) { var _b; try { const finalDbName = global.DSQL_USE_LOCAL @@ -34,27 +34,24 @@ function handleSocialDb(_a) { ? database : "datasquirel"; const dbAppend = global.DSQL_USE_LOCAL ? "" : `${finalDbName}.`; - const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `; - const existingSocialIdUserValues = [ - social_id.toString(), - social_platform, - ]; + const existingSocialUserQUery = `SELECT * FROM ${dbAppend}users WHERE email = ? AND social_login='1' AND social_platform = ? `; + const existingSocialUserValues = [email, social_platform]; if (debug) { - console.log("handleSocialDb:existingSocialIdUserQuery", existingSocialIdUserQuery); - console.log("handleSocialDb:existingSocialIdUserValues", existingSocialIdUserValues); + console.log("handleSocialDb:existingSocialUserQUery", existingSocialUserQUery); + console.log("handleSocialDb:existingSocialUserValues", existingSocialUserValues); } - let existingSocialIdUser = yield (0, varDatabaseDbHandler_1.default)({ + let existingSocialUser = yield (0, varDatabaseDbHandler_1.default)({ database: finalDbName, - queryString: existingSocialIdUserQuery, - queryValuesArray: existingSocialIdUserValues, + queryString: existingSocialUserQUery, + queryValuesArray: existingSocialUserValues, debug, }); if (debug) { - console.log("handleSocialDb:existingSocialIdUser", existingSocialIdUser); + console.log("handleSocialDb:existingSocialUser", existingSocialUser); } - if (existingSocialIdUser === null || existingSocialIdUser === void 0 ? void 0 : existingSocialIdUser[0]) { + if (existingSocialUser === null || existingSocialUser === void 0 ? void 0 : existingSocialUser[0]) { return yield (0, loginSocialUser_1.default)({ - user: existingSocialIdUser[0], + user: existingSocialUser[0], social_platform, invitation, database: finalDbName, @@ -89,33 +86,22 @@ function handleSocialDb(_a) { if (debug) { console.log("handleSocialDb:existingEmailOnly", existingEmailOnly); } - if (existingEmailOnly && existingEmailOnly[0]) { + if (existingEmailOnly === null || existingEmailOnly === void 0 ? void 0 : existingEmailOnly[0]) { return { success: false, payload: null, msg: "This Email is already taken", }; } - 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: finalDbName, - queryString: foundUserQuery, - queryValuesArray: foundUserQueryValues, - debug, - }); - if (foundUser && foundUser[0]) { - return yield (0, loginSocialUser_1.default)({ - user: payload, - social_platform, - invitation, - database: finalDbName, - additionalFields, - debug, - }); + else if (loginOnly) { + return { + success: false, + payload: null, + msg: "Social Account Creation Not allowed", + }; } const socialHashedPassword = (0, encrypt_1.default)({ - data: social_id.toString(), + data: email, }); const data = { social_login: "1", diff --git a/dist/package-shared/functions/api/users/social/api-github-login.js b/dist/package-shared/functions/api/users/social/api-github-login.js index faf21f1..f3cfd8d 100644 --- a/dist/package-shared/functions/api/users/social/api-github-login.js +++ b/dist/package-shared/functions/api/users/social/api-github-login.js @@ -77,7 +77,6 @@ function apiGithubLogin(_a) { email: gitHubUser.email, payload, social_platform: "github", - social_id: socialId, supEmail: email, additionalFields, }); 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 d5fa25e..35d7775 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 @@ -68,7 +68,6 @@ function apiGoogleLogin(_a) { email: email || "", payload: payloadObject, social_platform: "google", - social_id: sub, additionalFields, debug, loginOnly, diff --git a/dist/package-shared/types/index.d.ts b/dist/package-shared/types/index.d.ts index f0b7e91..8ff6997 100644 --- a/dist/package-shared/types/index.d.ts +++ b/dist/package-shared/types/index.d.ts @@ -1106,7 +1106,6 @@ export type APIGoogleLoginFunction = (params: APIGoogleLoginFunctionParams) => P */ export type HandleSocialDbFunctionParams = { database?: string; - social_id: string | number; email: string; social_platform: string; payload: any; diff --git a/package-shared/functions/api/social-login/handleSocialDb.ts b/package-shared/functions/api/social-login/handleSocialDb.ts index bd68876..72aea1e 100644 --- a/package-shared/functions/api/social-login/handleSocialDb.ts +++ b/package-shared/functions/api/social-login/handleSocialDb.ts @@ -16,7 +16,6 @@ import { */ export default async function handleSocialDb({ database, - social_id, email, social_platform, payload, @@ -34,40 +33,37 @@ export default async function handleSocialDb({ : "datasquirel"; const dbAppend = global.DSQL_USE_LOCAL ? "" : `${finalDbName}.`; - const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `; - const existingSocialIdUserValues = [ - social_id.toString(), - social_platform, - ]; + const existingSocialUserQUery = `SELECT * FROM ${dbAppend}users WHERE email = ? AND social_login='1' AND social_platform = ? `; + const existingSocialUserValues = [email, social_platform]; if (debug) { console.log( - "handleSocialDb:existingSocialIdUserQuery", - existingSocialIdUserQuery + "handleSocialDb:existingSocialUserQUery", + existingSocialUserQUery ); console.log( - "handleSocialDb:existingSocialIdUserValues", - existingSocialIdUserValues + "handleSocialDb:existingSocialUserValues", + existingSocialUserValues ); } - let existingSocialIdUser = await varDatabaseDbHandler({ + let existingSocialUser = await varDatabaseDbHandler({ database: finalDbName, - queryString: existingSocialIdUserQuery, - queryValuesArray: existingSocialIdUserValues, + queryString: existingSocialUserQUery, + queryValuesArray: existingSocialUserValues, debug, }); if (debug) { console.log( - "handleSocialDb:existingSocialIdUser", - existingSocialIdUser + "handleSocialDb:existingSocialUser", + existingSocialUser ); } - if (existingSocialIdUser?.[0]) { + if (existingSocialUser?.[0]) { return await loginSocialUser({ - user: existingSocialIdUser[0], + user: existingSocialUser[0], social_platform, invitation, database: finalDbName, @@ -111,37 +107,22 @@ export default async function handleSocialDb({ console.log("handleSocialDb:existingEmailOnly", existingEmailOnly); } - if (existingEmailOnly && existingEmailOnly[0]) { + if (existingEmailOnly?.[0]) { return { success: false, payload: null, msg: "This Email is already taken", }; - } - - 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 = await varDatabaseDbHandler({ - database: finalDbName, - queryString: foundUserQuery, - queryValuesArray: foundUserQueryValues, - debug, - }); - - if (foundUser && foundUser[0]) { - return await loginSocialUser({ - user: payload, - social_platform, - invitation, - database: finalDbName, - additionalFields, - debug, - }); + } else if (loginOnly) { + return { + success: false, + payload: null, + msg: "Social Account Creation Not allowed", + }; } const socialHashedPassword = encrypt({ - data: social_id.toString(), + data: email, }); const data: { [k: string]: any } = { diff --git a/package-shared/functions/api/users/social/api-github-login.ts b/package-shared/functions/api/users/social/api-github-login.ts index 98ba564..7521f75 100644 --- a/package-shared/functions/api/users/social/api-github-login.ts +++ b/package-shared/functions/api/users/social/api-github-login.ts @@ -90,7 +90,6 @@ export default async function apiGithubLogin({ email: gitHubUser.email, payload, social_platform: "github", - social_id: socialId, supEmail: email, additionalFields, }); 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 205cda4..f93316f 100644 --- a/package-shared/functions/api/users/social/api-google-login.ts +++ b/package-shared/functions/api/users/social/api-google-login.ts @@ -75,7 +75,6 @@ export default async function apiGoogleLogin({ email: email || "", payload: payloadObject, social_platform: "google", - social_id: sub, additionalFields, debug, loginOnly, diff --git a/package-shared/types/index.ts b/package-shared/types/index.ts index 0e7a459..976e2ae 100644 --- a/package-shared/types/index.ts +++ b/package-shared/types/index.ts @@ -1278,7 +1278,6 @@ export type APIGoogleLoginFunction = ( */ export type HandleSocialDbFunctionParams = { database?: string; - social_id: string | number; email: string; social_platform: string; payload: any; diff --git a/package.json b/package.json index 87923d6..60b8612 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "4.5.3", + "version": "4.5.4", "description": "Cloud-based SQL data management tool", "main": "dist/index.js", "bin": {