-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset-password-jwt.strategy.ts
34 lines (33 loc) · 1.11 KB
/
reset-password-jwt.strategy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import * as fs from 'fs';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { UserValidationService } from '../user-validation.service';
@Injectable()
export class ResetPasswordStrategy extends PassportStrategy(
Strategy,
'reset-password-jwt',
) {
constructor(
configService: ConfigService,
private authService: UserValidationService,
) {
const JWT_SECRET_FILE = configService.get<string>('JWT_SECRET_FILE');
const JWT_SECRET = fs.readFileSync(JWT_SECRET_FILE, 'utf8');
super({
jwtFromRequest: ExtractJwt.fromUrlQueryParameter('token'),
ignoreExpiration: false,
secretOrKey: JWT_SECRET,
});
}
async validate(payload: any) {
const { email } = payload;
const user = await this.authService.getUserForResetPassword(email);
return {
userId: user.userId,
email: user.email,
roleId: user.roleId,
};
}
}