fix(auth): added in the correct function for days between logins
This commit is contained in:
@@ -5,6 +5,7 @@ import {eq, sql} from "drizzle-orm";
|
|||||||
import {checkPassword} from "../utils/checkPassword.js";
|
import {checkPassword} from "../utils/checkPassword.js";
|
||||||
import {roleCheck} from "./userRoles/getUserAccess.js";
|
import {roleCheck} from "./userRoles/getUserAccess.js";
|
||||||
import {createLog} from "../../logger/logger.js";
|
import {createLog} from "../../logger/logger.js";
|
||||||
|
import {differenceInDays} from "date-fns";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticate a user and return a JWT.
|
* Authenticate a user and return a JWT.
|
||||||
@@ -50,7 +51,14 @@ export async function login(
|
|||||||
.set({lastLogin: sql`NOW()`})
|
.set({lastLogin: sql`NOW()`})
|
||||||
.where(eq(users.user_id, user[0].user_id))
|
.where(eq(users.user_id, user[0].user_id))
|
||||||
.returning({lastLogin: users.lastLogin});
|
.returning({lastLogin: users.lastLogin});
|
||||||
createLog("info", "lst", "auth", `Its been 5days since ${user[0].username} has logged in`);
|
createLog(
|
||||||
|
"info",
|
||||||
|
"lst",
|
||||||
|
"auth",
|
||||||
|
`Its been ${differenceInDays(lastLog[0]?.lastLogin ?? "", new Date(Date.now()))} days since ${
|
||||||
|
user[0].username
|
||||||
|
} has logged in`
|
||||||
|
);
|
||||||
//]);
|
//]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLog("error", "lst", "auth", "There was an error updating the user last login");
|
createLog("error", "lst", "auth", "There was an error updating the user last login");
|
||||||
|
|||||||
Reference in New Issue
Block a user