fix(logging): updated entire server side to the new logging system
This commit is contained in:
@@ -4,7 +4,7 @@ import {users} from "../../../../database/schema/users.js";
|
||||
import {eq, sql} from "drizzle-orm";
|
||||
import {checkPassword} from "../utils/checkPassword.js";
|
||||
import {roleCheck} from "./userRoles/getUserAccess.js";
|
||||
import {log} from "../../logger/logger.js";
|
||||
import {createLog} from "../../logger/logger.js";
|
||||
|
||||
/**
|
||||
* Authenticate a user and return a JWT.
|
||||
@@ -40,6 +40,7 @@ export async function login(
|
||||
email: user[0].email,
|
||||
roles: roles || null,
|
||||
role: user[0].role || null, // this should be removed onces full migration to v2 is completed
|
||||
prod: btoa(`${username.toLowerCase()}:${password}`),
|
||||
};
|
||||
|
||||
// update the user last login
|
||||
@@ -49,10 +50,10 @@ export async function login(
|
||||
.set({lastLogin: sql`NOW()`})
|
||||
.where(eq(users.user_id, user[0].user_id))
|
||||
.returning({lastLogin: users.lastLogin});
|
||||
log.info(`Its been 5days since ${user[0].username} has logged in`);
|
||||
createLog("info", "lst", "auth", `Its been 5days since ${user[0].username} has logged in`);
|
||||
//]);
|
||||
} catch (error) {
|
||||
log.error(error, "There was an error updating the user last login");
|
||||
createLog("error", "lst", "auth", "There was an error updating the user last login");
|
||||
}
|
||||
|
||||
const token = sign({user: userData}, secret, {expiresIn: expiresIn * 60});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {eq, sql} from "drizzle-orm";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {users} from "../../../../../database/schema/users.js";
|
||||
import {log} from "../../../logger/logger.js";
|
||||
import {createLog} from "../../../logger/logger.js";
|
||||
import {createPassword} from "../../utils/createPassword.js";
|
||||
|
||||
const blacklistedTokens = new Set();
|
||||
@@ -17,10 +17,9 @@ function isTokenBlacklisted(token: string) {
|
||||
|
||||
export const updateProfile = async (user: any, data: any, token: string) => {
|
||||
if (isTokenBlacklisted(token)) {
|
||||
log.warn(`${user.username} is trying to use a black listed token`);
|
||||
createLog("warn", user.username, "auth", `${user.username} is trying to use a black listed token`);
|
||||
throw Error("This token was already used");
|
||||
}
|
||||
log.info(`${user.user_id}`);
|
||||
|
||||
//re salt and encrypt the password
|
||||
try {
|
||||
@@ -33,6 +32,11 @@ export const updateProfile = async (user: any, data: any, token: string) => {
|
||||
|
||||
blacklistToken(token);
|
||||
} catch (error) {
|
||||
log.error(error, "There was an error updating the users profile");
|
||||
createLog(
|
||||
"error",
|
||||
user.username,
|
||||
"auth",
|
||||
`Error: ${JSON.stringify(error)}, "There was an error updating the users profile"`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user