chore(server): cleanup expired sessions (#7018)
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
|||||||
NotAcceptableException,
|
NotAcceptableException,
|
||||||
OnApplicationBootstrap,
|
OnApplicationBootstrap,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
import { Cron, CronExpression } from '@nestjs/schedule';
|
||||||
import type { User } from '@prisma/client';
|
import type { User } from '@prisma/client';
|
||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
import type { CookieOptions, Request, Response } from 'express';
|
import type { CookieOptions, Request, Response } from 'express';
|
||||||
@@ -455,4 +456,23 @@ export class AuthService implements OnApplicationBootstrap {
|
|||||||
to: email,
|
to: email,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)
|
||||||
|
async cleanExpiredSessions() {
|
||||||
|
await this.db.session.deleteMany({
|
||||||
|
where: {
|
||||||
|
expiresAt: {
|
||||||
|
lte: new Date(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.db.userSession.deleteMany({
|
||||||
|
where: {
|
||||||
|
expiresAt: {
|
||||||
|
lte: new Date(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ export class TokenService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)
|
@Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)
|
||||||
cleanExpiredTokens() {
|
async cleanExpiredTokens() {
|
||||||
return this.db.verificationToken.deleteMany({
|
await this.db.verificationToken.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
expiresAt: {
|
expiresAt: {
|
||||||
lte: new Date(),
|
lte: new Date(),
|
||||||
|
|||||||
Reference in New Issue
Block a user