Updates
This commit is contained in:
@@ -25,6 +25,7 @@ export default async function apiLoginUser({
|
||||
social,
|
||||
useLocal,
|
||||
dbUserId,
|
||||
debug,
|
||||
}: APILoginFunctionParams): Promise<APILoginFunctionReturn> {
|
||||
const dbFullName = grabDbFullName({ dbName: database, userId: dbUserId });
|
||||
|
||||
@@ -56,17 +57,23 @@ export default async function apiLoginUser({
|
||||
})
|
||||
: null;
|
||||
|
||||
console.log(
|
||||
`Logging in: Checking for Existing user in ${dbFullName} database.`
|
||||
);
|
||||
if (debug) {
|
||||
console.log("apiLoginUser:database:", dbFullName);
|
||||
console.log("apiLoginUser:Finding User ...");
|
||||
}
|
||||
|
||||
let foundUser = await varDatabaseDbHandler({
|
||||
queryString: `SELECT * FROM ${dbFullName}.users WHERE email = ? OR username = ?`,
|
||||
queryValuesArray: [email, username],
|
||||
database: dbFullName,
|
||||
useLocal,
|
||||
debug,
|
||||
});
|
||||
|
||||
if (debug) {
|
||||
console.log("apiLoginUser:foundUser:", foundUser);
|
||||
}
|
||||
|
||||
if ((!foundUser || !foundUser[0]) && !social)
|
||||
return {
|
||||
success: false,
|
||||
@@ -76,6 +83,10 @@ export default async function apiLoginUser({
|
||||
|
||||
let isPasswordCorrect = false;
|
||||
|
||||
if (debug) {
|
||||
console.log("apiLoginUser:isPasswordCorrect:", isPasswordCorrect);
|
||||
}
|
||||
|
||||
if (foundUser?.[0] && !email_login && skipPassword) {
|
||||
isPasswordCorrect = true;
|
||||
} else if (foundUser?.[0] && !email_login) {
|
||||
@@ -89,6 +100,10 @@ export default async function apiLoginUser({
|
||||
) {
|
||||
const tempCode: string = foundUser[0][email_login_field];
|
||||
|
||||
if (debug) {
|
||||
console.log("apiLoginUser:tempCode:", tempCode);
|
||||
}
|
||||
|
||||
if (!tempCode) throw new Error("No code Found!");
|
||||
|
||||
const tempCodeArray = tempCode.split("-");
|
||||
@@ -111,6 +126,11 @@ export default async function apiLoginUser({
|
||||
};
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
console.log("apiLoginUser:isPasswordCorrect:", isPasswordCorrect);
|
||||
console.log("apiLoginUser:email_login:", email_login);
|
||||
}
|
||||
|
||||
if (isPasswordCorrect && email_login) {
|
||||
const resetTempCode = await varDatabaseDbHandler({
|
||||
queryString: `UPDATE ${dbFullName}.users SET ${email_login_field} = '' WHERE email = ? OR username = ?`,
|
||||
@@ -144,6 +164,11 @@ export default async function apiLoginUser({
|
||||
date: Date.now(),
|
||||
};
|
||||
|
||||
if (debug) {
|
||||
console.log("apiLoginUser:userPayload:", userPayload);
|
||||
console.log("apiLoginUser:Sending Response Object ...");
|
||||
}
|
||||
|
||||
const resposeObject: APILoginFunctionReturn = {
|
||||
success: true,
|
||||
msg: "Login Successful",
|
||||
|
||||
Reference in New Issue
Block a user