Fix user last login not updating in database

This commit is contained in:
Aelita4 2024-02-10 18:25:19 +01:00
parent 6e529a9d74
commit 855bdb0144
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
2 changed files with 8 additions and 1 deletions

View File

@ -39,6 +39,11 @@ export const getUserByAccessToken = async(accessToken: string | AccessToken): Pr
} else return getUserById(accessToken.user as ObjectId)
}
export const updateLastLogin = async (user: User) => {
const users = await Users();
return users.updateOne({ username: user.username }, { $set: { lastLogin: new Date() } });
}
export const getUserBuildings = async (user: User): Promise<Array<Building>> => {
// const users = await Users();
// const user = await users.findOne({ username });

View File

@ -2,7 +2,7 @@
import Layout from '../layouts/Layout.astro';
import NavBar from '../components/NavBar.astro';
import { getUserByNickOrEmail } from '../lib/db/users';
import { getUserByNickOrEmail, updateLastLogin } from '../lib/db/users';
import { compare } from 'bcrypt';
@ -43,6 +43,8 @@ if(Astro.request.method === "POST") {
const token = (await res.json()).accessToken;
await updateLastLogin(user);
Astro.cookies.set("sessionToken", token, {
path: "/",
maxAge: sessionTime,