Updates
This commit is contained in:
parent
fdd3913f4f
commit
3695a75919
@ -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, useLocal, }: HandleSocialDbFunctionParams): Promise<APILoginFunctionReturn>;
|
||||
export default function handleSocialDb({ database, social_id, email, social_platform, payload, invitation, supEmail, additionalFields, useLocal, debug, }: HandleSocialDbFunctionParams): Promise<APILoginFunctionReturn>;
|
||||
|
@ -25,22 +25,30 @@ 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, useLocal, }) {
|
||||
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 dbAppend = database ? `${finalDbName}.` : "";
|
||||
const dbAppend = useLocal ? "" : `${finalDbName}.`;
|
||||
const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `;
|
||||
const existingSocialIdUserValues = [
|
||||
social_id.toString(),
|
||||
social_platform,
|
||||
];
|
||||
if (debug) {
|
||||
console.log("handleSocialDb:existingSocialIdUserQuery", existingSocialIdUserQuery);
|
||||
console.log("handleSocialDb:existingSocialIdUserValues", existingSocialIdUserValues);
|
||||
}
|
||||
let existingSocialIdUser = yield (0, varDatabaseDbHandler_1.default)({
|
||||
database: database ? database : "datasquirel",
|
||||
queryString: existingSocialIdUserQuery,
|
||||
queryValuesArray: existingSocialIdUserValues,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
if (existingSocialIdUser && existingSocialIdUser[0]) {
|
||||
if (debug) {
|
||||
console.log("handleSocialDb:existingSocialIdUser", existingSocialIdUser);
|
||||
}
|
||||
if (existingSocialIdUser === null || existingSocialIdUser === void 0 ? void 0 : existingSocialIdUser[0]) {
|
||||
return yield (0, loginSocialUser_1.default)({
|
||||
user: existingSocialIdUser[0],
|
||||
social_platform,
|
||||
@ -48,6 +56,7 @@ function handleSocialDb(_a) {
|
||||
database,
|
||||
additionalFields,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
}
|
||||
const finalEmail = email ? email : supEmail ? supEmail : null;
|
||||
@ -59,11 +68,18 @@ function handleSocialDb(_a) {
|
||||
};
|
||||
}
|
||||
const existingEmailOnlyQuery = `SELECT * FROM ${dbAppend}users WHERE email='${finalEmail}'`;
|
||||
if (debug) {
|
||||
console.log("handleSocialDb:existingEmailOnlyQuery", existingEmailOnlyQuery);
|
||||
}
|
||||
let existingEmailOnly = yield (0, varDatabaseDbHandler_1.default)({
|
||||
database: database ? database : "datasquirel",
|
||||
queryString: existingEmailOnlyQuery,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
if (debug) {
|
||||
console.log("handleSocialDb:existingEmailOnly", existingEmailOnly);
|
||||
}
|
||||
if (existingEmailOnly && existingEmailOnly[0]) {
|
||||
return {
|
||||
success: false,
|
||||
@ -78,6 +94,7 @@ function handleSocialDb(_a) {
|
||||
queryString: foundUserQuery,
|
||||
queryValuesArray: foundUserQueryValues,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
if (foundUser && foundUser[0]) {
|
||||
return yield (0, loginSocialUser_1.default)({
|
||||
@ -87,6 +104,7 @@ function handleSocialDb(_a) {
|
||||
database,
|
||||
additionalFields,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
}
|
||||
const socialHashedPassword = (0, encrypt_1.default)({
|
||||
@ -122,6 +140,7 @@ function handleSocialDb(_a) {
|
||||
database: database ? database : "datasquirel",
|
||||
queryString: newUserQueriedQuery,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
if (!newUserQueried || !newUserQueried[0])
|
||||
return {
|
||||
@ -180,6 +199,7 @@ function handleSocialDb(_a) {
|
||||
database,
|
||||
additionalFields,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
@ -11,6 +11,7 @@ type Param = {
|
||||
database?: string;
|
||||
additionalFields?: string[];
|
||||
useLocal?: boolean;
|
||||
debug?: boolean;
|
||||
};
|
||||
/**
|
||||
* Function to login social user
|
||||
@ -18,5 +19,5 @@ type Param = {
|
||||
* @description This function logs in the user after 'handleSocialDb' function finishes
|
||||
* the user creation or confirmation process
|
||||
*/
|
||||
export default function loginSocialUser({ user, social_platform, invitation, database, additionalFields, useLocal, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export default function loginSocialUser({ user, social_platform, invitation, database, additionalFields, useLocal, debug, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export {};
|
||||
|
@ -22,7 +22,7 @@ const varDatabaseDbHandler_1 = __importDefault(require("../../backend/varDatabas
|
||||
* the user creation or confirmation process
|
||||
*/
|
||||
function loginSocialUser(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ user, social_platform, invitation, database, additionalFields, useLocal, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ user, social_platform, invitation, database, additionalFields, useLocal, debug, }) {
|
||||
const finalDbName = database ? database : "datasquirel";
|
||||
const dbAppend = database ? `\`${finalDbName}\`.` : "";
|
||||
const foundUserQuery = `SELECT * FROM ${dbAppend}\`users\` WHERE email=? AND social_id=? AND social_platform=?`;
|
||||
@ -32,6 +32,7 @@ function loginSocialUser(_a) {
|
||||
queryString: foundUserQuery,
|
||||
queryValuesArray: foundUserValues,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
if (!(foundUser === null || foundUser === void 0 ? void 0 : foundUser[0]))
|
||||
return {
|
||||
|
@ -2,4 +2,4 @@ import { APIGoogleLoginFunctionParams, APILoginFunctionReturn } from "../../../.
|
||||
/**
|
||||
* # API google login
|
||||
*/
|
||||
export default function apiGoogleLogin({ token, database, additionalFields, additionalData, }: APIGoogleLoginFunctionParams): Promise<APILoginFunctionReturn>;
|
||||
export default function apiGoogleLogin({ token, database, additionalFields, additionalData, debug, }: APIGoogleLoginFunctionParams): Promise<APILoginFunctionReturn>;
|
||||
|
@ -20,7 +20,7 @@ const ejson_1 = __importDefault(require("../../../../utils/ejson"));
|
||||
* # API google login
|
||||
*/
|
||||
function apiGoogleLogin(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ token, database, additionalFields, additionalData, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ token, database, additionalFields, additionalData, debug, }) {
|
||||
try {
|
||||
const gUser = yield new Promise((resolve, reject) => {
|
||||
https_1.default
|
||||
@ -80,6 +80,7 @@ function apiGoogleLogin(_a) {
|
||||
social_platform: "google",
|
||||
social_id: sub,
|
||||
additionalFields,
|
||||
debug,
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
2
dist/package-shared/types/index.d.ts
vendored
2
dist/package-shared/types/index.d.ts
vendored
@ -1073,6 +1073,7 @@ export type APIGoogleLoginFunctionParams = {
|
||||
additionalData?: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
debug?: boolean;
|
||||
};
|
||||
export type APIGoogleLoginFunction = (params: APIGoogleLoginFunctionParams) => Promise<APILoginFunctionReturn>;
|
||||
/**
|
||||
@ -1088,6 +1089,7 @@ export type HandleSocialDbFunctionParams = {
|
||||
supEmail?: string;
|
||||
additionalFields?: string[];
|
||||
useLocal?: boolean;
|
||||
debug?: boolean;
|
||||
};
|
||||
export type HandleSocialDbFunctionReturn = {
|
||||
success: boolean;
|
||||
|
3
dist/users/social/google-auth.d.ts
vendored
3
dist/users/social/google-auth.d.ts
vendored
@ -13,9 +13,10 @@ type Param = {
|
||||
};
|
||||
apiUserID?: string | number;
|
||||
useLocal?: boolean;
|
||||
debug?: boolean;
|
||||
};
|
||||
/**
|
||||
* # SERVER FUNCTION: Login with google Function
|
||||
*/
|
||||
export default function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export default function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, debug, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export {};
|
||||
|
3
dist/users/social/google-auth.js
vendored
3
dist/users/social/google-auth.js
vendored
@ -22,7 +22,7 @@ const write_auth_files_1 = require("../../package-shared/functions/backend/auth/
|
||||
* # SERVER FUNCTION: Login with google Function
|
||||
*/
|
||||
function googleAuth(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, debug, }) {
|
||||
var _b;
|
||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@ -78,6 +78,7 @@ function googleAuth(_a) {
|
||||
additionalFields,
|
||||
database: DSQL_DB_NAME,
|
||||
additionalData,
|
||||
debug,
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
@ -24,10 +24,11 @@ export default async function handleSocialDb({
|
||||
supEmail,
|
||||
additionalFields,
|
||||
useLocal,
|
||||
debug,
|
||||
}: HandleSocialDbFunctionParams): Promise<APILoginFunctionReturn> {
|
||||
try {
|
||||
const finalDbName = database ? database : "datasquirel";
|
||||
const dbAppend = database ? `${finalDbName}.` : "";
|
||||
const dbAppend = useLocal ? "" : `${finalDbName}.`;
|
||||
|
||||
const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `;
|
||||
const existingSocialIdUserValues = [
|
||||
@ -35,14 +36,33 @@ export default async function handleSocialDb({
|
||||
social_platform,
|
||||
];
|
||||
|
||||
if (debug) {
|
||||
console.log(
|
||||
"handleSocialDb:existingSocialIdUserQuery",
|
||||
existingSocialIdUserQuery
|
||||
);
|
||||
console.log(
|
||||
"handleSocialDb:existingSocialIdUserValues",
|
||||
existingSocialIdUserValues
|
||||
);
|
||||
}
|
||||
|
||||
let existingSocialIdUser = await varDatabaseDbHandler({
|
||||
database: database ? database : "datasquirel",
|
||||
queryString: existingSocialIdUserQuery,
|
||||
queryValuesArray: existingSocialIdUserValues,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
|
||||
if (existingSocialIdUser && existingSocialIdUser[0]) {
|
||||
if (debug) {
|
||||
console.log(
|
||||
"handleSocialDb:existingSocialIdUser",
|
||||
existingSocialIdUser
|
||||
);
|
||||
}
|
||||
|
||||
if (existingSocialIdUser?.[0]) {
|
||||
return await loginSocialUser({
|
||||
user: existingSocialIdUser[0],
|
||||
social_platform,
|
||||
@ -50,6 +70,7 @@ export default async function handleSocialDb({
|
||||
database,
|
||||
additionalFields,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
}
|
||||
|
||||
@ -65,12 +86,24 @@ export default async function handleSocialDb({
|
||||
|
||||
const existingEmailOnlyQuery = `SELECT * FROM ${dbAppend}users WHERE email='${finalEmail}'`;
|
||||
|
||||
if (debug) {
|
||||
console.log(
|
||||
"handleSocialDb:existingEmailOnlyQuery",
|
||||
existingEmailOnlyQuery
|
||||
);
|
||||
}
|
||||
|
||||
let existingEmailOnly = await varDatabaseDbHandler({
|
||||
database: database ? database : "datasquirel",
|
||||
queryString: existingEmailOnlyQuery,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
|
||||
if (debug) {
|
||||
console.log("handleSocialDb:existingEmailOnly", existingEmailOnly);
|
||||
}
|
||||
|
||||
if (existingEmailOnly && existingEmailOnly[0]) {
|
||||
return {
|
||||
success: false,
|
||||
@ -87,6 +120,7 @@ export default async function handleSocialDb({
|
||||
queryString: foundUserQuery,
|
||||
queryValuesArray: foundUserQueryValues,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
|
||||
if (foundUser && foundUser[0]) {
|
||||
@ -97,6 +131,7 @@ export default async function handleSocialDb({
|
||||
database,
|
||||
additionalFields,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
}
|
||||
|
||||
@ -142,6 +177,7 @@ export default async function handleSocialDb({
|
||||
database: database ? database : "datasquirel",
|
||||
queryString: newUserQueriedQuery,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
|
||||
if (!newUserQueried || !newUserQueried[0])
|
||||
@ -220,6 +256,7 @@ export default async function handleSocialDb({
|
||||
database,
|
||||
additionalFields,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
|
@ -17,6 +17,7 @@ type Param = {
|
||||
database?: string;
|
||||
additionalFields?: string[];
|
||||
useLocal?: boolean;
|
||||
debug?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -32,6 +33,7 @@ export default async function loginSocialUser({
|
||||
database,
|
||||
additionalFields,
|
||||
useLocal,
|
||||
debug,
|
||||
}: Param): Promise<APILoginFunctionReturn> {
|
||||
const finalDbName = database ? database : "datasquirel";
|
||||
const dbAppend = database ? `\`${finalDbName}\`.` : "";
|
||||
@ -44,6 +46,7 @@ export default async function loginSocialUser({
|
||||
queryString: foundUserQuery,
|
||||
queryValuesArray: foundUserValues,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
|
||||
if (!foundUser?.[0])
|
||||
|
@ -15,6 +15,7 @@ export default async function apiGoogleLogin({
|
||||
database,
|
||||
additionalFields,
|
||||
additionalData,
|
||||
debug,
|
||||
}: APIGoogleLoginFunctionParams): Promise<APILoginFunctionReturn> {
|
||||
try {
|
||||
const gUser: GoogleOauth2User | undefined = await new Promise(
|
||||
@ -87,6 +88,7 @@ export default async function apiGoogleLogin({
|
||||
social_platform: "google",
|
||||
social_id: sub,
|
||||
additionalFields,
|
||||
debug,
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
|
@ -1257,6 +1257,7 @@ export type APIGoogleLoginFunctionParams = {
|
||||
database: string;
|
||||
additionalFields?: string[];
|
||||
additionalData?: { [key: string]: string | number };
|
||||
debug?: boolean;
|
||||
};
|
||||
|
||||
export type APIGoogleLoginFunction = (
|
||||
@ -1276,6 +1277,7 @@ export type HandleSocialDbFunctionParams = {
|
||||
supEmail?: string;
|
||||
additionalFields?: string[];
|
||||
useLocal?: boolean;
|
||||
debug?: boolean;
|
||||
};
|
||||
|
||||
export type HandleSocialDbFunctionReturn = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "3.7.5",
|
||||
"version": "3.7.6",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
@ -17,6 +17,7 @@ type Param = {
|
||||
additionalData?: { [s: string]: string | number };
|
||||
apiUserID?: string | number;
|
||||
useLocal?: boolean;
|
||||
debug?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -33,6 +34,7 @@ export default async function googleAuth({
|
||||
additionalData,
|
||||
apiUserID,
|
||||
useLocal,
|
||||
debug,
|
||||
}: Param): Promise<APILoginFunctionReturn> {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@ -101,6 +103,7 @@ export default async function googleAuth({
|
||||
additionalFields,
|
||||
database: DSQL_DB_NAME,
|
||||
additionalData,
|
||||
debug,
|
||||
});
|
||||
} else {
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user