From 8fe65e5c8d2a354aa7f258fe8cb4a4caed1430f1 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Tue, 10 Dec 2024 19:44:11 +0100 Subject: [PATCH] Updates --- package.json | 2 +- users/social/google-auth.d.ts | 16 ++++--------- users/social/google-auth.js | 45 +++++++---------------------------- 3 files changed, 13 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index 017a2e2..fd48b3a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "2.9.0", + "version": "2.9.1", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": { diff --git a/users/social/google-auth.d.ts b/users/social/google-auth.d.ts index 8241e71..0c153e5 100644 --- a/users/social/google-auth.d.ts +++ b/users/social/google-auth.d.ts @@ -1,10 +1,4 @@ export = googleAuth; -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ /** * @typedef {object | null} FunctionReturn * @property {boolean} success - Did the function run successfully? @@ -21,26 +15,24 @@ export = googleAuth; * @param {object} params - main params object * @param {string} [params.key] - API full access key * @param {string} params.token - Google access token gotten from the client side - * @param {string} params.database - Target database name(slug) + * @param {string} [params.database] - Target database name * @param {http.ServerResponse} [params.response] - HTTPS response object * @param {string} [params.encryptionKey] - Encryption key * @param {string} [params.encryptionSalt] - Encryption salt * @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object - * @param {boolean} [params.user_id] - User ID - * @param {string | number} [params.apiUserID] - Required for setting of cookies + * @param {string | number} [params.apiUserID] - API user ID * @param {boolean} [params.useLocal] - Whether to use a remote database instead of API * * @returns { Promise } */ -declare function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, user_id, apiUserID, useLocal, }: { +declare function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, apiUserID, useLocal, }: { key?: string; token: string; - database: string; + database?: string; response?: http.ServerResponse; encryptionKey?: string; encryptionSalt?: string; additionalFields?: string[]; - user_id?: boolean; apiUserID?: string | number; useLocal?: boolean; }): Promise; diff --git a/users/social/google-auth.js b/users/social/google-auth.js index 24c39c1..504f029 100644 --- a/users/social/google-auth.js +++ b/users/social/google-auth.js @@ -1,10 +1,5 @@ // @ts-check -/** - * ============================================================================== - * Imports - * ============================================================================== - */ const http = require("http"); const fs = require("fs"); const path = require("path"); @@ -16,13 +11,6 @@ const { writeAuthFile, } = require("../../package-shared/functions/backend/auth/write-auth-files"); -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ -/** ****************************************************************************** */ - /** * @typedef {object | null} FunctionReturn * @property {boolean} success - Did the function run successfully? @@ -40,13 +28,12 @@ const { * @param {object} params - main params object * @param {string} [params.key] - API full access key * @param {string} params.token - Google access token gotten from the client side - * @param {string} params.database - Target database name(slug) + * @param {string} [params.database] - Target database name * @param {http.ServerResponse} [params.response] - HTTPS response object * @param {string} [params.encryptionKey] - Encryption key * @param {string} [params.encryptionSalt] - Encryption salt * @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object - * @param {boolean} [params.user_id] - User ID - * @param {string | number} [params.apiUserID] - Required for setting of cookies + * @param {string | number} [params.apiUserID] - API user ID * @param {boolean} [params.useLocal] - Whether to use a remote database instead of API * * @returns { Promise } @@ -59,7 +46,6 @@ async function googleAuth({ encryptionKey, encryptionSalt, additionalFields, - user_id, apiUserID, useLocal, }) { @@ -134,24 +120,11 @@ async function googleAuth({ DSQL_DB_NAME?.match(/./) && useLocal ) { - /** @type {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined | undefined} */ - let dbSchema; - - try { - const localDbSchemaPath = path.resolve( - process.cwd(), - "dsql.schema.json" - ); - dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8")); - } catch (error) {} - - if (dbSchema && apiUserID) { - httpResponse = await apiGoogleLogin({ - token, - additionalFields, - database: DSQL_DB_NAME, - }); - } + httpResponse = await apiGoogleLogin({ + token, + additionalFields, + database: DSQL_DB_NAME, + }); } else { /** * Make https request @@ -180,7 +153,7 @@ async function googleAuth({ port, hostname: host, path: `/api/user/${ - user_id || grabedHostNames.user_id + apiUserID || grabedHostNames.user_id }/google-login`, }, @@ -227,8 +200,6 @@ async function googleAuth({ userId: apiUserID || process.env.DSQL_API_USER_ID, }); - console.log("apiUserID", apiUserID); - if (httpResponse.csrf) { writeAuthFile( httpResponse.csrf,