This commit is contained in:
batche
2022-11-07 17:37:30 +01:00
parent 24b68dc767
commit a77b9e99dc
10 changed files with 8 additions and 20 deletions

View File

@@ -4,15 +4,12 @@ import { AuthenticationService } from './authentication.service';
import { Response } from 'express';
import { TwoFaDto } from './dto/2fa.dto';
import { UsersService } from 'src/users/users.service';
import { User } from 'src/users/entities/user.entity';
import { request } from 'http';
@Controller('auth')
export class AuthenticationController {
constructor(private authService: AuthenticationService,
private userService: UsersService,
// private jwtservice: JwtService
) {}
/**
@@ -74,10 +71,8 @@ export class AuthenticationController {
const isCodeIsValid = await this.authService.verify2FaCode(request.user, twoFaCode);
if (isCodeIsValid === false)
{
request.session.destroy();
throw new UnauthorizedException('Wrong Code.');
}
await this.userService.enableTwoFactorAuth(request.user.id);
}
}

View File

@@ -15,7 +15,7 @@ export class FortyTwoAuthGuard extends AuthGuard('42') {
export class AuthenticateGuard implements CanActivate {
async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest();
console.log(request.isAuthenticated());
console.log("Is User authenticated : " + request.isAuthenticated());
return request.isAuthenticated();
}
}

View File

@@ -22,9 +22,6 @@ export class FortyTwoStrategy extends PassportStrategy(Strategy, "42") {
const user = await this.authenticationService.validateUser(userDTO);
if (!user)
throw new UnauthorizedException();
if (!user.isEnabledTwoFactorAuth)
return user;
if (userDTO.isEnabledTwoFactorAuth)
return user;
return user;
}
}