Updates
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
APILoginFunctionReturn,
|
||||
DATASQUIREL_LoggedInUser,
|
||||
} from "../../../types";
|
||||
import grabDbFullName from "../../../utils/grab-db-full-name";
|
||||
import varDatabaseDbHandler from "../../backend/varDatabaseDbHandler";
|
||||
import hashPassword from "../../dsql/hashPassword";
|
||||
|
||||
@@ -23,8 +24,9 @@ export default async function apiLoginUser({
|
||||
skipPassword,
|
||||
social,
|
||||
useLocal,
|
||||
dbUserId,
|
||||
}: APILoginFunctionParams): Promise<APILoginFunctionReturn> {
|
||||
const dbFullName = database.replace(/[^a-z0-9_]/g, "");
|
||||
const dbFullName = grabDbFullName({ dbName: database, userId: dbUserId });
|
||||
|
||||
/**
|
||||
* Check input validity
|
||||
@@ -54,7 +56,9 @@ export default async function apiLoginUser({
|
||||
})
|
||||
: null;
|
||||
|
||||
console.log("Finding DSQL User ...");
|
||||
console.log(
|
||||
`Logging in: Checking for Existing user in ${dbFullName} database.`
|
||||
);
|
||||
|
||||
let foundUser = await varDatabaseDbHandler({
|
||||
queryString: `SELECT * FROM ${dbFullName}.users WHERE email = ? OR username = ?`,
|
||||
@@ -63,8 +67,6 @@ export default async function apiLoginUser({
|
||||
useLocal,
|
||||
});
|
||||
|
||||
console.log("foundUser", foundUser);
|
||||
|
||||
if ((!foundUser || !foundUser[0]) && !social)
|
||||
return {
|
||||
success: false,
|
||||
|
||||
@@ -158,6 +158,7 @@ export interface PackageUserLoginRequestBody {
|
||||
social?: boolean;
|
||||
dbSchema?: DSQL_DatabaseSchemaType;
|
||||
skipPassword?: boolean;
|
||||
dbUserId: string | number;
|
||||
}
|
||||
|
||||
export interface PackageUserLoginLocalBody {
|
||||
@@ -1208,6 +1209,7 @@ export type APILoginFunctionParams = {
|
||||
skipPassword?: boolean;
|
||||
social?: boolean;
|
||||
useLocal?: boolean;
|
||||
dbUserId?: number | string;
|
||||
};
|
||||
export type APILoginFunctionReturn = {
|
||||
success: boolean;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
type Param = {
|
||||
dbName: string;
|
||||
userId?: string | number;
|
||||
};
|
||||
|
||||
/**
|
||||
* # Grab Database Full Name
|
||||
*/
|
||||
export default function grabDbFullName({ dbName, userId }: Param): string {
|
||||
const sanitizedName = dbName.replace(/[^a-z0-9\_]/g, "");
|
||||
const cleanedDbName = sanitizedName.replace(/datasquirel_user_\d+_/, "");
|
||||
|
||||
if (!userId) return cleanedDbName;
|
||||
|
||||
const dbNamePrefix = `datasquirel_user_${userId}_`;
|
||||
|
||||
return dbNamePrefix + cleanedDbName;
|
||||
}
|
||||
Reference in New Issue
Block a user