diff --git a/nestjs-BE/server/src/refresh-tokens/refresh-tokens.service.ts b/nestjs-BE/server/src/refresh-tokens/refresh-tokens.service.ts index cee9d580..1cf11334 100644 --- a/nestjs-BE/server/src/refresh-tokens/refresh-tokens.service.ts +++ b/nestjs-BE/server/src/refresh-tokens/refresh-tokens.service.ts @@ -1,9 +1,10 @@ import { Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { JwtService } from '@nestjs/jwt'; -import { PrismaService } from '../prisma/prisma.service'; -import { v4 as uuid } from 'uuid'; +import { Cron, CronExpression } from '@nestjs/schedule'; import { Prisma, RefreshToken } from '@prisma/client'; -import { ConfigService } from '@nestjs/config'; +import { v4 as uuid } from 'uuid'; +import { PrismaService } from '../prisma/prisma.service'; import { getExpiryDate } from '../utils/date'; @Injectable() @@ -44,6 +45,13 @@ export class RefreshTokensService { } } + @Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT) + async deleteExpiredRefreshTokens() { + await this.prisma.refreshToken.deleteMany({ + where: { expiryDate: { lt: new Date() } }, + }); + } + private createToken(): string { const refreshToken = this.jwtService.sign( { uuid: uuid() },