add permissions to roles

This commit is contained in:
rubikscraft
2022-03-12 15:10:22 +01:00
parent 0aa897fa8d
commit b29b88d7b6
27 changed files with 601 additions and 230 deletions

View File

@@ -2,17 +2,17 @@ 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 { UsersService } from '../../../collections/userdb/userdb.service';
import { EUserBackend } from '../../../models/entities/user.entity';
import { AuthManagerService } from '../auth.service';
@Injectable()
export class LocalAuthStrategy extends PassportStrategy(Strategy, 'local') {
constructor(private authService: AuthManagerService) {
constructor(private usersService: UsersService) {
super();
}
async validate(username: string, password: string): AsyncFailable<EUserBackend> {
const user = await this.authService.authenticate(username, password);
const user = await this.usersService.authenticate(username, password);
if (HasFailed(user)) {
throw new UnauthorizedException();
}