Updates
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import addAdminUserOnLogin from "../../backend/addAdminUserOnLogin";
|
||||
import varDatabaseDbHandler from "../../backend/varDatabaseDbHandler";
|
||||
import { APILoginFunctionReturn } from "../../../types";
|
||||
import {
|
||||
APILoginFunctionReturn,
|
||||
DATASQUIREL_LoggedInUser,
|
||||
} from "../../../types";
|
||||
|
||||
type Param = {
|
||||
user: {
|
||||
@@ -31,8 +34,9 @@ export default async function loginSocialUser({
|
||||
useLocal,
|
||||
}: Param): Promise<APILoginFunctionReturn> {
|
||||
const finalDbName = database ? database : "datasquirel";
|
||||
const dbAppend = database ? `\`${finalDbName}\`.` : "";
|
||||
|
||||
const foundUserQuery = `SELECT * FROM \`${finalDbName}\`.\`users\` WHERE email=? AND social_id=? AND social_platform=?`;
|
||||
const foundUserQuery = `SELECT * FROM ${dbAppend}\`users\` WHERE email=? AND social_id=? AND social_platform=?`;
|
||||
const foundUserValues = [user.email, user.social_id, social_platform];
|
||||
|
||||
const foundUser = await varDatabaseDbHandler({
|
||||
@@ -53,8 +57,7 @@ export default async function loginSocialUser({
|
||||
"-" +
|
||||
Math.random().toString(36).substring(2);
|
||||
|
||||
/** @type {import("../../../types").DATASQUIREL_LoggedInUser} */
|
||||
let userPayload: import("../../../types").DATASQUIREL_LoggedInUser = {
|
||||
let userPayload: DATASQUIREL_LoggedInUser = {
|
||||
id: foundUser[0].id,
|
||||
first_name: foundUser[0].first_name,
|
||||
last_name: foundUser[0].last_name,
|
||||
@@ -86,8 +89,7 @@ export default async function loginSocialUser({
|
||||
});
|
||||
}
|
||||
|
||||
/** @type {import("../../../types").APILoginFunctionReturn} */
|
||||
let result: import("../../../types").APILoginFunctionReturn = {
|
||||
let result: APILoginFunctionReturn = {
|
||||
success: true,
|
||||
payload: userPayload,
|
||||
csrf: csrfKey,
|
||||
|
||||
@@ -65,7 +65,6 @@ export default async function apiGoogleLogin({
|
||||
|
||||
const { given_name, family_name, email, sub, picture } = gUser;
|
||||
|
||||
/** @type {Object<string, any>} */
|
||||
let payloadObject: { [s: string]: any } = {
|
||||
email: email,
|
||||
first_name: given_name,
|
||||
|
||||
@@ -23,7 +23,7 @@ export default async function varDatabaseDbHandler({
|
||||
useLocal,
|
||||
debug,
|
||||
}: Param): Promise<any> {
|
||||
let CONNECTION = grabDSQLConnection({ fa: true });
|
||||
let CONNECTION = grabDSQLConnection({ fa: true, local: useLocal });
|
||||
if (useLocal) CONNECTION = grabDSQLConnection({ local: true });
|
||||
if (database?.match(/^datasquirel$/)) CONNECTION = grabDSQLConnection();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user