Updates
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user