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) {
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,

View File

@ -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
*

View File

@ -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) {

View File

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

View File

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

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_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,
});

View File

@ -27,7 +27,11 @@ export default async function handleSocialDb({
debug,
}: HandleSocialDbFunctionParams): Promise<APILoginFunctionReturn> {
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,

View File

@ -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
*

View File

@ -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(

View File

@ -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;

View File

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

View File

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

View File

@ -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,
});