src/auth/local.strategy.ts
PassportStrategy(Strategy)
Methods |
|
constructor(authService: AuthService)
|
||||||
Defined in src/auth/local.strategy.ts:8
|
||||||
Parameters :
|
Async validate |
validate(username: string, password: string)
|
Defined in src/auth/local.strategy.ts:13
|
Returns :
Promise<UserCredentials>
|
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-local';
import { UserCredentials } from './auth.model';
import { AuthService } from './auth.service';
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authService: AuthService) {
super();
}
async validate(username: string, password: string): Promise<UserCredentials> {
const user = await this.authService.validateUser(username, password);
if (!user) {
throw new UnauthorizedException();
}
return user;
}
}