Files
twenty/server/src/core/auth/guards/google-provider-enabled.guard.ts
Charles Bochet 9ea765fcfd Make auth module optional to conditionnaly load auth providers (#518)
* Make auth module optional to conditionnaly load auth providers

* Fixes
2023-07-05 15:46:09 +02:00

18 lines
693 B
TypeScript

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 NotFoundException('Google auth is not enabled');
}
new GoogleStrategy(this.environmentService);
return true;
}
}