Skip to content

Commit

Permalink
Merge pull request #367 from boostcampwm2023/BE-feature/delete-expire…
Browse files Browse the repository at this point in the history
…d-tokens

만료 토큰 제거
  • Loading branch information
Conut-1 authored Dec 3, 2024
2 parents 5717346 + 2734b2b commit 6e46d8e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions nestjs-BE/server/src/refresh-tokens/refresh-tokens.service.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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() },
Expand Down

0 comments on commit 6e46d8e

Please sign in to comment.