mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-19 11:12:00 +10:00
🚀 release v3.0.0
This commit is contained in:
22
server/src/auth/strategy/jwt.strategy.ts
Normal file
22
server/src/auth/strategy/jwt.strategy.ts
Normal file
@ -0,0 +1,22 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
18
server/src/auth/strategy/local.strategy.ts
Normal file
18
server/src/auth/strategy/local.strategy.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Strategy } from 'passport-local';
|
||||
|
||||
import { User } from '@/users/entities/user.entity';
|
||||
|
||||
import { AuthService } from '../auth.service';
|
||||
|
||||
@Injectable()
|
||||
export class LocalStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(private authService: AuthService) {
|
||||
super({ usernameField: 'identifier' });
|
||||
}
|
||||
|
||||
async validate(identifier: string, password: string): Promise<User> {
|
||||
return this.authService.getUser(identifier, password);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user