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