mirror of
https://github.com/jakobkordez/ham-reserve.git
synced 2025-08-04 04:07:40 +00:00
Initial commit
This commit is contained in:
18
nest-api/src/auth/strategies/local.strategy.ts
Normal file
18
nest-api/src/auth/strategies/local.strategy.ts
Normal file
@ -0,0 +1,18 @@
|
||||
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();
|
||||
}
|
||||
|
||||
async validate(username: string, password: string): Promise<any> {
|
||||
const user = await this.authService.validateUser(username, password);
|
||||
if (!user) throw new UnauthorizedException();
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user