This commit is contained in:
Benjamin Toby 2025-01-20 08:42:35 +01:00
parent 3695a75919
commit c210e6ca46
13 changed files with 44 additions and 49 deletions

View File

@ -27,7 +27,11 @@ const loginSocialUser_1 = __importDefault(require("./loginSocialUser"));
function handleSocialDb(_a) { function handleSocialDb(_a) {
return __awaiter(this, arguments, void 0, function* ({ database, social_id, email, social_platform, payload, invitation, supEmail, additionalFields, useLocal, debug, }) { return __awaiter(this, arguments, void 0, function* ({ database, social_id, email, social_platform, payload, invitation, supEmail, additionalFields, useLocal, debug, }) {
try { try {
const finalDbName = database ? database : "datasquirel"; const finalDbName = useLocal
? undefined
: database
? database
: "datasquirel";
const dbAppend = useLocal ? "" : `${finalDbName}.`; const dbAppend = useLocal ? "" : `${finalDbName}.`;
const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `; const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `;
const existingSocialIdUserValues = [ const existingSocialIdUserValues = [
@ -39,7 +43,7 @@ function handleSocialDb(_a) {
console.log("handleSocialDb:existingSocialIdUserValues", existingSocialIdUserValues); console.log("handleSocialDb:existingSocialIdUserValues", existingSocialIdUserValues);
} }
let existingSocialIdUser = yield (0, varDatabaseDbHandler_1.default)({ let existingSocialIdUser = yield (0, varDatabaseDbHandler_1.default)({
database: database ? database : "datasquirel", database: finalDbName,
queryString: existingSocialIdUserQuery, queryString: existingSocialIdUserQuery,
queryValuesArray: existingSocialIdUserValues, queryValuesArray: existingSocialIdUserValues,
useLocal, useLocal,
@ -53,7 +57,7 @@ function handleSocialDb(_a) {
user: existingSocialIdUser[0], user: existingSocialIdUser[0],
social_platform, social_platform,
invitation, invitation,
database, database: finalDbName,
additionalFields, additionalFields,
useLocal, useLocal,
debug, debug,
@ -72,7 +76,7 @@ function handleSocialDb(_a) {
console.log("handleSocialDb:existingEmailOnlyQuery", existingEmailOnlyQuery); console.log("handleSocialDb:existingEmailOnlyQuery", existingEmailOnlyQuery);
} }
let existingEmailOnly = yield (0, varDatabaseDbHandler_1.default)({ let existingEmailOnly = yield (0, varDatabaseDbHandler_1.default)({
database: database ? database : "datasquirel", database: finalDbName,
queryString: existingEmailOnlyQuery, queryString: existingEmailOnlyQuery,
useLocal, useLocal,
debug, 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 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 foundUserQueryValues = [finalEmail, social_platform, social_id];
const foundUser = yield (0, varDatabaseDbHandler_1.default)({ const foundUser = yield (0, varDatabaseDbHandler_1.default)({
database: database ? database : "datasquirel", database: finalDbName,
queryString: foundUserQuery, queryString: foundUserQuery,
queryValuesArray: foundUserQueryValues, queryValuesArray: foundUserQueryValues,
useLocal, useLocal,
@ -101,7 +105,7 @@ function handleSocialDb(_a) {
user: payload, user: payload,
social_platform, social_platform,
invitation, invitation,
database, database: finalDbName,
additionalFields, additionalFields,
useLocal, useLocal,
debug, debug,
@ -119,9 +123,9 @@ function handleSocialDb(_a) {
data[key] = payload[key]; data[key] = payload[key];
}); });
const newUser = yield (0, addDbEntry_1.default)({ const newUser = yield (0, addDbEntry_1.default)({
dbContext: database ? "Dsql User" : undefined, dbContext: finalDbName ? "Dsql User" : undefined,
paradigm: database ? "Full Access" : undefined, paradigm: finalDbName ? "Full Access" : undefined,
dbFullName: database ? database : "datasquirel", dbFullName: finalDbName,
tableName: "users", tableName: "users",
duplicateColumnName: "email", duplicateColumnName: "email",
duplicateColumnValue: finalEmail, duplicateColumnValue: finalEmail,
@ -137,7 +141,7 @@ function handleSocialDb(_a) {
} }
const newUserQueriedQuery = `SELECT * FROM ${dbAppend}users WHERE id='${newUser.insertId}'`; const newUserQueriedQuery = `SELECT * FROM ${dbAppend}users WHERE id='${newUser.insertId}'`;
const newUserQueried = yield (0, varDatabaseDbHandler_1.default)({ const newUserQueried = yield (0, varDatabaseDbHandler_1.default)({
database: database ? database : "datasquirel", database: finalDbName,
queryString: newUserQueriedQuery, queryString: newUserQueriedQuery,
useLocal, useLocal,
debug, debug,
@ -196,7 +200,7 @@ function handleSocialDb(_a) {
user: newUserQueried[0], user: newUserQueried[0],
social_platform, social_platform,
invitation, invitation,
database, database: finalDbName,
additionalFields, additionalFields,
useLocal, useLocal,
debug, debug,

View File

@ -44,16 +44,6 @@ function apiGoogleLogin(_a) {
}); });
if (!(gUser === null || gUser === void 0 ? void 0 : gUser.email_verified)) if (!(gUser === null || gUser === void 0 ? void 0 : gUser.email_verified))
throw new Error("No Google User."); 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 * Create new user folder and file
* *

View File

@ -30,6 +30,7 @@ function varDatabaseDbHandler(_a) {
if (debug) { if (debug) {
console.log(`varDatabaseDbHandler:query:`, queryString); console.log(`varDatabaseDbHandler:query:`, queryString);
console.log(`varDatabaseDbHandler:values:`, queryValuesArray); console.log(`varDatabaseDbHandler:values:`, queryValuesArray);
console.log(`varDatabaseDbHandler:CONNECTION:`, CONNECTION.getConfig());
} }
let results = yield (0, conn_db_handler_1.default)(CONNECTION, queryString, queryValuesArray); let results = yield (0, conn_db_handler_1.default)(CONNECTION, queryString, queryValuesArray);
if (debug) { if (debug) {

View File

@ -1068,7 +1068,7 @@ export type APIGetUserFunctionParams = {
*/ */
export type APIGoogleLoginFunctionParams = { export type APIGoogleLoginFunctionParams = {
token: string; token: string;
database: string; database?: string;
additionalFields?: string[]; additionalFields?: string[];
additionalData?: { additionalData?: {
[key: string]: string | number; [key: string]: string | number;

View File

@ -59,6 +59,7 @@ values) {
} }
catch (error) { catch (error) {
console.log(`connDbHandler Error: ${error.message}`); console.log(`connDbHandler Error: ${error.message}`);
console.log(conn === null || conn === void 0 ? void 0 : conn.getConfig());
return null; return null;
} }
finally { finally {

View File

@ -73,10 +73,12 @@ function googleAuth(_a) {
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) && (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(/./)) && (DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
useLocal) { useLocal) {
if (debug) {
console.log(`Google login with Local Paradigm ...`);
}
httpResponse = yield (0, api_google_login_1.default)({ httpResponse = yield (0, api_google_login_1.default)({
token, token,
additionalFields, additionalFields,
database: DSQL_DB_NAME,
additionalData, additionalData,
debug, debug,
}); });

View File

@ -27,7 +27,11 @@ export default async function handleSocialDb({
debug, debug,
}: HandleSocialDbFunctionParams): Promise<APILoginFunctionReturn> { }: HandleSocialDbFunctionParams): Promise<APILoginFunctionReturn> {
try { try {
const finalDbName = database ? database : "datasquirel"; const finalDbName = useLocal
? undefined
: database
? database
: "datasquirel";
const dbAppend = useLocal ? "" : `${finalDbName}.`; const dbAppend = useLocal ? "" : `${finalDbName}.`;
const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `; 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({ let existingSocialIdUser = await varDatabaseDbHandler({
database: database ? database : "datasquirel", database: finalDbName,
queryString: existingSocialIdUserQuery, queryString: existingSocialIdUserQuery,
queryValuesArray: existingSocialIdUserValues, queryValuesArray: existingSocialIdUserValues,
useLocal, useLocal,
@ -67,7 +71,7 @@ export default async function handleSocialDb({
user: existingSocialIdUser[0], user: existingSocialIdUser[0],
social_platform, social_platform,
invitation, invitation,
database, database: finalDbName,
additionalFields, additionalFields,
useLocal, useLocal,
debug, debug,
@ -94,7 +98,7 @@ export default async function handleSocialDb({
} }
let existingEmailOnly = await varDatabaseDbHandler({ let existingEmailOnly = await varDatabaseDbHandler({
database: database ? database : "datasquirel", database: finalDbName,
queryString: existingEmailOnlyQuery, queryString: existingEmailOnlyQuery,
useLocal, useLocal,
debug, debug,
@ -116,7 +120,7 @@ export default async function handleSocialDb({
const foundUserQueryValues = [finalEmail, social_platform, social_id]; const foundUserQueryValues = [finalEmail, social_platform, social_id];
const foundUser = await varDatabaseDbHandler({ const foundUser = await varDatabaseDbHandler({
database: database ? database : "datasquirel", database: finalDbName,
queryString: foundUserQuery, queryString: foundUserQuery,
queryValuesArray: foundUserQueryValues, queryValuesArray: foundUserQueryValues,
useLocal, useLocal,
@ -128,7 +132,7 @@ export default async function handleSocialDb({
user: payload, user: payload,
social_platform, social_platform,
invitation, invitation,
database, database: finalDbName,
additionalFields, additionalFields,
useLocal, useLocal,
debug, debug,
@ -150,9 +154,9 @@ export default async function handleSocialDb({
}); });
const newUser = await addDbEntry({ const newUser = await addDbEntry({
dbContext: database ? "Dsql User" : undefined, dbContext: finalDbName ? "Dsql User" : undefined,
paradigm: database ? "Full Access" : undefined, paradigm: finalDbName ? "Full Access" : undefined,
dbFullName: database ? database : "datasquirel", dbFullName: finalDbName,
tableName: "users", tableName: "users",
duplicateColumnName: "email", duplicateColumnName: "email",
duplicateColumnValue: finalEmail, duplicateColumnValue: finalEmail,
@ -174,7 +178,7 @@ export default async function handleSocialDb({
const newUserQueriedQuery = `SELECT * FROM ${dbAppend}users WHERE id='${newUser.insertId}'`; const newUserQueriedQuery = `SELECT * FROM ${dbAppend}users WHERE id='${newUser.insertId}'`;
const newUserQueried = await varDatabaseDbHandler({ const newUserQueried = await varDatabaseDbHandler({
database: database ? database : "datasquirel", database: finalDbName,
queryString: newUserQueriedQuery, queryString: newUserQueriedQuery,
useLocal, useLocal,
debug, debug,
@ -253,7 +257,7 @@ export default async function handleSocialDb({
user: newUserQueried[0], user: newUserQueried[0],
social_platform, social_platform,
invitation, invitation,
database, database: finalDbName,
additionalFields, additionalFields,
useLocal, useLocal,
debug, debug,

View File

@ -46,18 +46,6 @@ export default async function apiGoogleLogin({
if (!gUser?.email_verified) throw new Error("No Google User."); 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 * Create new user folder and file
* *

View File

@ -30,6 +30,7 @@ export default async function varDatabaseDbHandler({
if (debug) { if (debug) {
console.log(`varDatabaseDbHandler:query:`, queryString); console.log(`varDatabaseDbHandler:query:`, queryString);
console.log(`varDatabaseDbHandler:values:`, queryValuesArray); console.log(`varDatabaseDbHandler:values:`, queryValuesArray);
console.log(`varDatabaseDbHandler:CONNECTION:`, CONNECTION.getConfig());
} }
let results = await connDbHandler( let results = await connDbHandler(

View File

@ -1254,7 +1254,7 @@ export type APIGetUserFunctionParams = {
*/ */
export type APIGoogleLoginFunctionParams = { export type APIGoogleLoginFunctionParams = {
token: string; token: string;
database: string; database?: string;
additionalFields?: string[]; additionalFields?: string[];
additionalData?: { [key: string]: string | number }; additionalData?: { [key: string]: string | number };
debug?: boolean; debug?: boolean;

View File

@ -56,6 +56,7 @@ export default async function connDbHandler<ReturnType = any>(
} }
} catch (error: any) { } catch (error: any) {
console.log(`connDbHandler Error: ${error.message}`); console.log(`connDbHandler Error: ${error.message}`);
console.log(conn?.getConfig());
return null; return null;
} finally { } finally {
conn?.end(); conn?.end();

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "3.7.6", "version": "3.7.7",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {

View File

@ -98,10 +98,13 @@ export default async function googleAuth({
DSQL_DB_NAME?.match(/./) && DSQL_DB_NAME?.match(/./) &&
useLocal useLocal
) { ) {
if (debug) {
console.log(`Google login with Local Paradigm ...`);
}
httpResponse = await apiGoogleLogin({ httpResponse = await apiGoogleLogin({
token, token,
additionalFields, additionalFields,
database: DSQL_DB_NAME,
additionalData, additionalData,
debug, debug,
}); });