File size: 1,008 Bytes
7b850b7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import { Strategy } from 'passport-local';
import { PassportStrategy } from '@nestjs/passport';
import {
HttpException,
HttpStatus,
Injectable,
UnauthorizedException,
} from '@nestjs/common';
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,
isAdmin: boolean = false,
): Promise<any> {
console.log(`IDENTIFIER =>`, identifier);
const user = await this.authService.validateUser(identifier, password);
if (!user) {
throw new UnauthorizedException('Incorrect username or password');
}
if ((user && user.deletedAt) || (user && user.isDeleted === true)) {
throw new HttpException(
'Your account has been deleted',
HttpStatus.FORBIDDEN,
);
}
return user;
}
}
|