-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathlocal.strategy.ts
More file actions
28 lines (22 loc) · 787 Bytes
/
local.strategy.ts
File metadata and controls
28 lines (22 loc) · 787 Bytes
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
import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-local';
import { CustomUnauthorizedException } from 'src/common/exceptions';
import { AuthService } from '../auth.service';
import { SignInInput } from '../inputs/auth.input';
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy, 'local') {
constructor(private readonly authService: AuthService) {
super({
usernameField: 'username',
passwordField: 'password',
});
}
validate(username: string, password: string): Promise<SignInInput> {
const user = this.authService.validateUser({ username, password });
if (!user) {
throw new CustomUnauthorizedException();
}
return user;
}
}