Updates
This commit is contained in:
		
							parent
							
								
									cc29a3c107
								
							
						
					
					
						commit
						cd4a2f7902
					
				@ -2,4 +2,4 @@ import { APILoginFunctionReturn, HandleSocialDbFunctionParams } from "../../../t
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * # Handle Social DB
 | 
					 * # Handle Social DB
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export default function handleSocialDb({ database, social_id, email, social_platform, payload, invitation, supEmail, additionalFields, debug, loginOnly, }: HandleSocialDbFunctionParams): Promise<APILoginFunctionReturn>;
 | 
					export default function handleSocialDb({ database, email, social_platform, payload, invitation, supEmail, additionalFields, debug, loginOnly, }: HandleSocialDbFunctionParams): Promise<APILoginFunctionReturn>;
 | 
				
			||||||
 | 
				
			|||||||
@ -25,7 +25,7 @@ const loginSocialUser_1 = __importDefault(require("./loginSocialUser"));
 | 
				
			|||||||
 * # Handle Social DB
 | 
					 * # Handle Social DB
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function handleSocialDb(_a) {
 | 
					function handleSocialDb(_a) {
 | 
				
			||||||
    return __awaiter(this, arguments, void 0, function* ({ database, social_id, email, social_platform, payload, invitation, supEmail, additionalFields, debug, loginOnly, }) {
 | 
					    return __awaiter(this, arguments, void 0, function* ({ database, email, social_platform, payload, invitation, supEmail, additionalFields, debug, loginOnly, }) {
 | 
				
			||||||
        var _b;
 | 
					        var _b;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            const finalDbName = global.DSQL_USE_LOCAL
 | 
					            const finalDbName = global.DSQL_USE_LOCAL
 | 
				
			||||||
@ -34,27 +34,24 @@ function handleSocialDb(_a) {
 | 
				
			|||||||
                    ? database
 | 
					                    ? database
 | 
				
			||||||
                    : "datasquirel";
 | 
					                    : "datasquirel";
 | 
				
			||||||
            const dbAppend = global.DSQL_USE_LOCAL ? "" : `${finalDbName}.`;
 | 
					            const dbAppend = global.DSQL_USE_LOCAL ? "" : `${finalDbName}.`;
 | 
				
			||||||
            const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `;
 | 
					            const existingSocialUserQUery = `SELECT * FROM ${dbAppend}users WHERE email = ? AND social_login='1' AND social_platform = ? `;
 | 
				
			||||||
            const existingSocialIdUserValues = [
 | 
					            const existingSocialUserValues = [email, social_platform];
 | 
				
			||||||
                social_id.toString(),
 | 
					 | 
				
			||||||
                social_platform,
 | 
					 | 
				
			||||||
            ];
 | 
					 | 
				
			||||||
            if (debug) {
 | 
					            if (debug) {
 | 
				
			||||||
                console.log("handleSocialDb:existingSocialIdUserQuery", existingSocialIdUserQuery);
 | 
					                console.log("handleSocialDb:existingSocialUserQUery", existingSocialUserQUery);
 | 
				
			||||||
                console.log("handleSocialDb:existingSocialIdUserValues", existingSocialIdUserValues);
 | 
					                console.log("handleSocialDb:existingSocialUserValues", existingSocialUserValues);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            let existingSocialIdUser = yield (0, varDatabaseDbHandler_1.default)({
 | 
					            let existingSocialUser = yield (0, varDatabaseDbHandler_1.default)({
 | 
				
			||||||
                database: finalDbName,
 | 
					                database: finalDbName,
 | 
				
			||||||
                queryString: existingSocialIdUserQuery,
 | 
					                queryString: existingSocialUserQUery,
 | 
				
			||||||
                queryValuesArray: existingSocialIdUserValues,
 | 
					                queryValuesArray: existingSocialUserValues,
 | 
				
			||||||
                debug,
 | 
					                debug,
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            if (debug) {
 | 
					            if (debug) {
 | 
				
			||||||
                console.log("handleSocialDb:existingSocialIdUser", existingSocialIdUser);
 | 
					                console.log("handleSocialDb:existingSocialUser", existingSocialUser);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (existingSocialIdUser === null || existingSocialIdUser === void 0 ? void 0 : existingSocialIdUser[0]) {
 | 
					            if (existingSocialUser === null || existingSocialUser === void 0 ? void 0 : existingSocialUser[0]) {
 | 
				
			||||||
                return yield (0, loginSocialUser_1.default)({
 | 
					                return yield (0, loginSocialUser_1.default)({
 | 
				
			||||||
                    user: existingSocialIdUser[0],
 | 
					                    user: existingSocialUser[0],
 | 
				
			||||||
                    social_platform,
 | 
					                    social_platform,
 | 
				
			||||||
                    invitation,
 | 
					                    invitation,
 | 
				
			||||||
                    database: finalDbName,
 | 
					                    database: finalDbName,
 | 
				
			||||||
@ -89,33 +86,22 @@ function handleSocialDb(_a) {
 | 
				
			|||||||
            if (debug) {
 | 
					            if (debug) {
 | 
				
			||||||
                console.log("handleSocialDb:existingEmailOnly", existingEmailOnly);
 | 
					                console.log("handleSocialDb:existingEmailOnly", existingEmailOnly);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (existingEmailOnly && existingEmailOnly[0]) {
 | 
					            if (existingEmailOnly === null || existingEmailOnly === void 0 ? void 0 : existingEmailOnly[0]) {
 | 
				
			||||||
                return {
 | 
					                return {
 | 
				
			||||||
                    success: false,
 | 
					                    success: false,
 | 
				
			||||||
                    payload: null,
 | 
					                    payload: null,
 | 
				
			||||||
                    msg: "This Email is already taken",
 | 
					                    msg: "This Email is already taken",
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            const foundUserQuery = `SELECT * FROM ${dbAppend}users WHERE email=? AND social_login='1' AND social_platform=? AND social_id=?`;
 | 
					            else if (loginOnly) {
 | 
				
			||||||
            const foundUserQueryValues = [finalEmail, social_platform, social_id];
 | 
					                return {
 | 
				
			||||||
            const foundUser = yield (0, varDatabaseDbHandler_1.default)({
 | 
					                    success: false,
 | 
				
			||||||
                database: finalDbName,
 | 
					                    payload: null,
 | 
				
			||||||
                queryString: foundUserQuery,
 | 
					                    msg: "Social Account Creation Not allowed",
 | 
				
			||||||
                queryValuesArray: foundUserQueryValues,
 | 
					                };
 | 
				
			||||||
                debug,
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            if (foundUser && foundUser[0]) {
 | 
					 | 
				
			||||||
                return yield (0, loginSocialUser_1.default)({
 | 
					 | 
				
			||||||
                    user: payload,
 | 
					 | 
				
			||||||
                    social_platform,
 | 
					 | 
				
			||||||
                    invitation,
 | 
					 | 
				
			||||||
                    database: finalDbName,
 | 
					 | 
				
			||||||
                    additionalFields,
 | 
					 | 
				
			||||||
                    debug,
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            const socialHashedPassword = (0, encrypt_1.default)({
 | 
					            const socialHashedPassword = (0, encrypt_1.default)({
 | 
				
			||||||
                data: social_id.toString(),
 | 
					                data: email,
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            const data = {
 | 
					            const data = {
 | 
				
			||||||
                social_login: "1",
 | 
					                social_login: "1",
 | 
				
			||||||
 | 
				
			|||||||
@ -77,7 +77,6 @@ function apiGithubLogin(_a) {
 | 
				
			|||||||
            email: gitHubUser.email,
 | 
					            email: gitHubUser.email,
 | 
				
			||||||
            payload,
 | 
					            payload,
 | 
				
			||||||
            social_platform: "github",
 | 
					            social_platform: "github",
 | 
				
			||||||
            social_id: socialId,
 | 
					 | 
				
			||||||
            supEmail: email,
 | 
					            supEmail: email,
 | 
				
			||||||
            additionalFields,
 | 
					            additionalFields,
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
				
			|||||||
@ -68,7 +68,6 @@ function apiGoogleLogin(_a) {
 | 
				
			|||||||
                email: email || "",
 | 
					                email: email || "",
 | 
				
			||||||
                payload: payloadObject,
 | 
					                payload: payloadObject,
 | 
				
			||||||
                social_platform: "google",
 | 
					                social_platform: "google",
 | 
				
			||||||
                social_id: sub,
 | 
					 | 
				
			||||||
                additionalFields,
 | 
					                additionalFields,
 | 
				
			||||||
                debug,
 | 
					                debug,
 | 
				
			||||||
                loginOnly,
 | 
					                loginOnly,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								dist/package-shared/types/index.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								dist/package-shared/types/index.d.ts
									
									
									
									
										vendored
									
									
								
							@ -1106,7 +1106,6 @@ export type APIGoogleLoginFunction = (params: APIGoogleLoginFunctionParams) => P
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
export type HandleSocialDbFunctionParams = {
 | 
					export type HandleSocialDbFunctionParams = {
 | 
				
			||||||
    database?: string;
 | 
					    database?: string;
 | 
				
			||||||
    social_id: string | number;
 | 
					 | 
				
			||||||
    email: string;
 | 
					    email: string;
 | 
				
			||||||
    social_platform: string;
 | 
					    social_platform: string;
 | 
				
			||||||
    payload: any;
 | 
					    payload: any;
 | 
				
			||||||
 | 
				
			|||||||
@ -16,7 +16,6 @@ import {
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
export default async function handleSocialDb({
 | 
					export default async function handleSocialDb({
 | 
				
			||||||
    database,
 | 
					    database,
 | 
				
			||||||
    social_id,
 | 
					 | 
				
			||||||
    email,
 | 
					    email,
 | 
				
			||||||
    social_platform,
 | 
					    social_platform,
 | 
				
			||||||
    payload,
 | 
					    payload,
 | 
				
			||||||
@ -34,40 +33,37 @@ export default async function handleSocialDb({
 | 
				
			|||||||
            : "datasquirel";
 | 
					            : "datasquirel";
 | 
				
			||||||
        const dbAppend = global.DSQL_USE_LOCAL ? "" : `${finalDbName}.`;
 | 
					        const dbAppend = global.DSQL_USE_LOCAL ? "" : `${finalDbName}.`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const existingSocialIdUserQuery = `SELECT * FROM ${dbAppend}users WHERE social_id = ? AND social_login='1' AND social_platform = ? `;
 | 
					        const existingSocialUserQUery = `SELECT * FROM ${dbAppend}users WHERE email = ? AND social_login='1' AND social_platform = ? `;
 | 
				
			||||||
        const existingSocialIdUserValues = [
 | 
					        const existingSocialUserValues = [email, social_platform];
 | 
				
			||||||
            social_id.toString(),
 | 
					 | 
				
			||||||
            social_platform,
 | 
					 | 
				
			||||||
        ];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (debug) {
 | 
					        if (debug) {
 | 
				
			||||||
            console.log(
 | 
					            console.log(
 | 
				
			||||||
                "handleSocialDb:existingSocialIdUserQuery",
 | 
					                "handleSocialDb:existingSocialUserQUery",
 | 
				
			||||||
                existingSocialIdUserQuery
 | 
					                existingSocialUserQUery
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
            console.log(
 | 
					            console.log(
 | 
				
			||||||
                "handleSocialDb:existingSocialIdUserValues",
 | 
					                "handleSocialDb:existingSocialUserValues",
 | 
				
			||||||
                existingSocialIdUserValues
 | 
					                existingSocialUserValues
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let existingSocialIdUser = await varDatabaseDbHandler({
 | 
					        let existingSocialUser = await varDatabaseDbHandler({
 | 
				
			||||||
            database: finalDbName,
 | 
					            database: finalDbName,
 | 
				
			||||||
            queryString: existingSocialIdUserQuery,
 | 
					            queryString: existingSocialUserQUery,
 | 
				
			||||||
            queryValuesArray: existingSocialIdUserValues,
 | 
					            queryValuesArray: existingSocialUserValues,
 | 
				
			||||||
            debug,
 | 
					            debug,
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (debug) {
 | 
					        if (debug) {
 | 
				
			||||||
            console.log(
 | 
					            console.log(
 | 
				
			||||||
                "handleSocialDb:existingSocialIdUser",
 | 
					                "handleSocialDb:existingSocialUser",
 | 
				
			||||||
                existingSocialIdUser
 | 
					                existingSocialUser
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (existingSocialIdUser?.[0]) {
 | 
					        if (existingSocialUser?.[0]) {
 | 
				
			||||||
            return await loginSocialUser({
 | 
					            return await loginSocialUser({
 | 
				
			||||||
                user: existingSocialIdUser[0],
 | 
					                user: existingSocialUser[0],
 | 
				
			||||||
                social_platform,
 | 
					                social_platform,
 | 
				
			||||||
                invitation,
 | 
					                invitation,
 | 
				
			||||||
                database: finalDbName,
 | 
					                database: finalDbName,
 | 
				
			||||||
@ -111,37 +107,22 @@ export default async function handleSocialDb({
 | 
				
			|||||||
            console.log("handleSocialDb:existingEmailOnly", existingEmailOnly);
 | 
					            console.log("handleSocialDb:existingEmailOnly", existingEmailOnly);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (existingEmailOnly && existingEmailOnly[0]) {
 | 
					        if (existingEmailOnly?.[0]) {
 | 
				
			||||||
            return {
 | 
					            return {
 | 
				
			||||||
                success: false,
 | 
					                success: false,
 | 
				
			||||||
                payload: null,
 | 
					                payload: null,
 | 
				
			||||||
                msg: "This Email is already taken",
 | 
					                msg: "This Email is already taken",
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
        }
 | 
					        } else if (loginOnly) {
 | 
				
			||||||
 | 
					            return {
 | 
				
			||||||
        const foundUserQuery = `SELECT * FROM ${dbAppend}users WHERE email=? AND social_login='1' AND social_platform=? AND social_id=?`;
 | 
					                success: false,
 | 
				
			||||||
        const foundUserQueryValues = [finalEmail, social_platform, social_id];
 | 
					                payload: null,
 | 
				
			||||||
 | 
					                msg: "Social Account Creation Not allowed",
 | 
				
			||||||
        const foundUser = await varDatabaseDbHandler({
 | 
					            };
 | 
				
			||||||
            database: finalDbName,
 | 
					 | 
				
			||||||
            queryString: foundUserQuery,
 | 
					 | 
				
			||||||
            queryValuesArray: foundUserQueryValues,
 | 
					 | 
				
			||||||
            debug,
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (foundUser && foundUser[0]) {
 | 
					 | 
				
			||||||
            return await loginSocialUser({
 | 
					 | 
				
			||||||
                user: payload,
 | 
					 | 
				
			||||||
                social_platform,
 | 
					 | 
				
			||||||
                invitation,
 | 
					 | 
				
			||||||
                database: finalDbName,
 | 
					 | 
				
			||||||
                additionalFields,
 | 
					 | 
				
			||||||
                debug,
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const socialHashedPassword = encrypt({
 | 
					        const socialHashedPassword = encrypt({
 | 
				
			||||||
            data: social_id.toString(),
 | 
					            data: email,
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const data: { [k: string]: any } = {
 | 
					        const data: { [k: string]: any } = {
 | 
				
			||||||
 | 
				
			|||||||
@ -90,7 +90,6 @@ export default async function apiGithubLogin({
 | 
				
			|||||||
        email: gitHubUser.email,
 | 
					        email: gitHubUser.email,
 | 
				
			||||||
        payload,
 | 
					        payload,
 | 
				
			||||||
        social_platform: "github",
 | 
					        social_platform: "github",
 | 
				
			||||||
        social_id: socialId,
 | 
					 | 
				
			||||||
        supEmail: email,
 | 
					        supEmail: email,
 | 
				
			||||||
        additionalFields,
 | 
					        additionalFields,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
				
			|||||||
@ -75,7 +75,6 @@ export default async function apiGoogleLogin({
 | 
				
			|||||||
            email: email || "",
 | 
					            email: email || "",
 | 
				
			||||||
            payload: payloadObject,
 | 
					            payload: payloadObject,
 | 
				
			||||||
            social_platform: "google",
 | 
					            social_platform: "google",
 | 
				
			||||||
            social_id: sub,
 | 
					 | 
				
			||||||
            additionalFields,
 | 
					            additionalFields,
 | 
				
			||||||
            debug,
 | 
					            debug,
 | 
				
			||||||
            loginOnly,
 | 
					            loginOnly,
 | 
				
			||||||
 | 
				
			|||||||
@ -1278,7 +1278,6 @@ export type APIGoogleLoginFunction = (
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
export type HandleSocialDbFunctionParams = {
 | 
					export type HandleSocialDbFunctionParams = {
 | 
				
			||||||
    database?: string;
 | 
					    database?: string;
 | 
				
			||||||
    social_id: string | number;
 | 
					 | 
				
			||||||
    email: string;
 | 
					    email: string;
 | 
				
			||||||
    social_platform: string;
 | 
					    social_platform: string;
 | 
				
			||||||
    payload: any;
 | 
					    payload: any;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    "name": "@moduletrace/datasquirel",
 | 
					    "name": "@moduletrace/datasquirel",
 | 
				
			||||||
    "version": "4.5.3",
 | 
					    "version": "4.5.4",
 | 
				
			||||||
    "description": "Cloud-based SQL data management tool",
 | 
					    "description": "Cloud-based SQL data management tool",
 | 
				
			||||||
    "main": "dist/index.js",
 | 
					    "main": "dist/index.js",
 | 
				
			||||||
    "bin": {
 | 
					    "bin": {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user