relocate auth module

This commit is contained in:
rubikscraft
2022-03-07 20:19:58 +01:00
parent fd4a5c2293
commit a4854d02ae
14 changed files with 82 additions and 68 deletions

View File

@@ -0,0 +1,22 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-local';
import { AsyncFailable, HasFailed } from 'picsur-shared/dist/types';
import { EUserBackend } from '../../../models/entities/user.entity';
import { AuthManagerService } from '../auth.service';
@Injectable()
export class LocalAuthStrategy extends PassportStrategy(Strategy, 'local') {
constructor(private authService: AuthManagerService) {
super();
}
async validate(username: string, password: string): AsyncFailable<EUserBackend> {
const user = await this.authService.authenticate(username, password);
if (HasFailed(user)) {
throw new UnauthorizedException();
}
return user;
}
}