Fix user last login not updating in database
This commit is contained in:
parent
6e529a9d74
commit
855bdb0144
|
@ -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 });
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue