Add last logged in to User and delete users who are older than 1 year with no sessions

This commit is contained in:
William Oldham
2023-11-04 11:35:17 +00:00
parent b0af87a6b1
commit 04175fafae
4 changed files with 47 additions and 5 deletions

View File

@@ -62,13 +62,15 @@ export const loginAuthRouter = makeRouter((app) => {
throw new StatusError('User cannot be found', 401);
}
user.lastLoggedIn = new Date();
const session = makeSession(
user.id,
body.device,
req.headers['user-agent'],
);
await em.persistAndFlush(session);
await em.persistAndFlush([session, user]);
return {
session: formatSession(session),

View File

@@ -64,11 +64,14 @@ export const manageAuthRouter = makeRouter((app) => {
user.namespace = body.namespace;
user.publicKey = body.publicKey;
user.profile = body.profile;
user.lastLoggedIn = new Date();
const session = makeSession(
user.id,
body.device,
req.headers['user-agent'],
);
await em.persistAndFlush([user, session]);
getMetrics().user.inc({ namespace: body.namespace }, 1);
return {