Make auth module optional to conditionnaly load auth providers (#518)

* Make auth module optional to conditionnaly load auth providers

* Fixes
This commit is contained in:
Charles Bochet
2023-07-05 15:46:09 +02:00
committed by GitHub
parent 463994df1f
commit 9ea765fcfd
6 changed files with 31 additions and 35 deletions

View File

@ -1,14 +1,17 @@
import { Injectable, CanActivate, HttpException } from '@nestjs/common';
import { Injectable, CanActivate, NotFoundException } from '@nestjs/common';
import { Observable } from 'rxjs';
import { EnvironmentService } from 'src/integrations/environment/environment.service';
import { GoogleStrategy } from '../strategies/google.auth.strategy';
@Injectable()
export class GoogleProviderEnabledGuard implements CanActivate {
constructor(private readonly environmentService: EnvironmentService) {}
canActivate(): boolean | Promise<boolean> | Observable<boolean> {
if (!this.environmentService.getAuthGoogleEnabled()) {
throw new HttpException('Google auth is not enabled', 404);
throw new NotFoundException('Google auth is not enabled');
}
new GoogleStrategy(this.environmentService);
return true;
}
}