21 lines
594 B
TypeScript
21 lines
594 B
TypeScript
|
|
import { Strategy } from 'passport-local';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|
import { AuthService } from '../auth.service';
|
|
|
|
@Injectable()
|
|
export class LoginStrategy extends PassportStrategy(Strategy, 'login') {
|
|
constructor(private authService: AuthService) {
|
|
super();
|
|
}
|
|
|
|
async validate(username: string, password: string): Promise<any> {
|
|
const user = await this.authService.validate(username, password);
|
|
if (!user) {
|
|
throw new UnauthorizedException();
|
|
}
|
|
return user;
|
|
}
|
|
}
|