mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-15 09:11:57 +10:00
23 lines
750 B
TypeScript
23 lines
750 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
|
|
import { User } from '@/users/entities/user.entity';
|
|
import { UsersService } from '@/users/users.service';
|
|
|
|
@Injectable()
|
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
constructor(configService: ConfigService, private readonly usersService: UsersService) {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
secretOrKey: configService.get<string>('auth.jwtSecret'),
|
|
ignoreExpiration: false,
|
|
});
|
|
}
|
|
|
|
validate({ id }: User): Promise<User> {
|
|
return this.usersService.findById(id);
|
|
}
|
|
}
|