File tree 1 file changed +11
-3
lines changed
nestjs-BE/server/src/refresh-tokens
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@nestjs/common' ;
2
+ import { ConfigService } from '@nestjs/config' ;
2
3
import { JwtService } from '@nestjs/jwt' ;
3
- import { PrismaService } from '../prisma/prisma.service' ;
4
- import { v4 as uuid } from 'uuid' ;
4
+ import { Cron , CronExpression } from '@nestjs/schedule' ;
5
5
import { Prisma , RefreshToken } from '@prisma/client' ;
6
- import { ConfigService } from '@nestjs/config' ;
6
+ import { v4 as uuid } from 'uuid' ;
7
+ import { PrismaService } from '../prisma/prisma.service' ;
7
8
import { getExpiryDate } from '../utils/date' ;
8
9
9
10
@Injectable ( )
@@ -44,6 +45,13 @@ export class RefreshTokensService {
44
45
}
45
46
}
46
47
48
+ @Cron ( CronExpression . EVERY_DAY_AT_MIDNIGHT )
49
+ async deleteExpiredRefreshTokens ( ) {
50
+ await this . prisma . refreshToken . deleteMany ( {
51
+ where : { expiryDate : { lt : new Date ( ) } } ,
52
+ } ) ;
53
+ }
54
+
47
55
private createToken ( ) : string {
48
56
const refreshToken = this . jwtService . sign (
49
57
{ uuid : uuid ( ) } ,
You can’t perform that action at this time.
0 commit comments