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:
@ -3,7 +3,6 @@ import { JwtModule } from '@nestjs/jwt';
|
||||
import { JwtAuthStrategy } from './strategies/jwt.auth.strategy';
|
||||
import { AuthService } from './services/auth.service';
|
||||
import { GoogleAuthController } from './controllers/google-auth.controller';
|
||||
import { GoogleStrategy } from './strategies/google.auth.strategy';
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { UserModule } from '../user/user.module';
|
||||
import { VerifyAuthController } from './controllers/verify-auth.controller';
|
||||
@ -30,7 +29,6 @@ const jwtModule = JwtModule.registerAsync({
|
||||
AuthService,
|
||||
TokenService,
|
||||
JwtAuthStrategy,
|
||||
GoogleStrategy,
|
||||
PrismaService,
|
||||
AuthResolver,
|
||||
],
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,17 +16,10 @@ export type GoogleRequest = Request & {
|
||||
@Injectable()
|
||||
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
constructor(environmentService: EnvironmentService) {
|
||||
const isAuthGoogleEnabled = environmentService.getAuthGoogleEnabled();
|
||||
super({
|
||||
clientID: isAuthGoogleEnabled
|
||||
? environmentService.getAuthGoogleClientId()
|
||||
: 'disabled',
|
||||
clientSecret: isAuthGoogleEnabled
|
||||
? environmentService.getAuthGoogleClientSecret()
|
||||
: 'disabled',
|
||||
callbackURL: isAuthGoogleEnabled
|
||||
? environmentService.getAuthGoogleCallbackUrl()
|
||||
: 'disabled',
|
||||
clientID: environmentService.getAuthGoogleClientId(),
|
||||
clientSecret: environmentService.getAuthGoogleClientSecret(),
|
||||
callbackURL: environmentService.getAuthGoogleCallbackUrl(),
|
||||
scope: ['email', 'profile'],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user