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