This commit is contained in:
Benjamin Toby 2024-12-10 19:44:11 +01:00
parent b3b906ba8c
commit 8fe65e5c8d
3 changed files with 13 additions and 50 deletions

View File

@ -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": {

View File

@ -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<FunctionReturn> }
*/
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<FunctionReturn>;

View File

@ -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<FunctionReturn> }
@ -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,