All files / src/modules/auth/strategies local.strategy.ts

0% Statements 0/13
0% Branches 0/1
0% Functions 0/2
0% Lines 0/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                                           
import { Strategy } from 'passport-local';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthService } from '../auth.service';
 
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
  constructor(private authService: AuthService) {
    super({
      usernameField: 'email',
    });
  }
 
  async validate(email: string, password: string): Promise<any> {
    const user = await this.authService.validateUser(email, password);
    Iif (!user) {
      throw new UnauthorizedException('Invalid credentials');
    }
    return user;
  }
}