fix: provider return type in SSO guards

This commit is contained in:
Mir Arif Hasan
2023-07-29 15:02:54 +06:00
parent a72b1feda5
commit c3d03d7162
3 changed files with 15 additions and 6 deletions

View File

@@ -1,14 +1,17 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
import { AuthProvider, authProviderCheck, throwHTTPErr } from '../helper'; import { AuthProvider, authProviderCheck, throwHTTPErr } from '../helper';
import { Observable } from 'rxjs';
@Injectable() @Injectable()
export class GithubSSOGuard extends AuthGuard('github') implements CanActivate { export class GithubSSOGuard extends AuthGuard('github') implements CanActivate {
canActivate(context: ExecutionContext): boolean { canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
if (!authProviderCheck(AuthProvider.GITHUB)) if (!authProviderCheck(AuthProvider.GITHUB))
throwHTTPErr({ message: 'GitHub auth is not enabled', statusCode: 404 }); throwHTTPErr({ message: 'GitHub auth is not enabled', statusCode: 404 });
return true; return super.canActivate(context);
} }
getAuthenticateOptions(context: ExecutionContext) { getAuthenticateOptions(context: ExecutionContext) {

View File

@@ -1,14 +1,17 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
import { AuthProvider, authProviderCheck, throwHTTPErr } from '../helper'; import { AuthProvider, authProviderCheck, throwHTTPErr } from '../helper';
import { Observable } from 'rxjs';
@Injectable() @Injectable()
export class GoogleSSOGuard extends AuthGuard('google') implements CanActivate { export class GoogleSSOGuard extends AuthGuard('google') implements CanActivate {
canActivate(context: ExecutionContext): boolean { canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
if (!authProviderCheck(AuthProvider.GOOGLE)) if (!authProviderCheck(AuthProvider.GOOGLE))
throwHTTPErr({ message: 'Google auth is not enabled', statusCode: 404 }); throwHTTPErr({ message: 'Google auth is not enabled', statusCode: 404 });
return true; return super.canActivate(context);
} }
getAuthenticateOptions(context: ExecutionContext) { getAuthenticateOptions(context: ExecutionContext) {

View File

@@ -1,20 +1,23 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
import { AuthProvider, authProviderCheck, throwHTTPErr } from '../helper'; import { AuthProvider, authProviderCheck, throwHTTPErr } from '../helper';
import { Observable } from 'rxjs';
@Injectable() @Injectable()
export class MicrosoftSSOGuard export class MicrosoftSSOGuard
extends AuthGuard('microsoft') extends AuthGuard('microsoft')
implements CanActivate implements CanActivate
{ {
canActivate(context: ExecutionContext): boolean { canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
if (!authProviderCheck(AuthProvider.MICROSOFT)) if (!authProviderCheck(AuthProvider.MICROSOFT))
throwHTTPErr({ throwHTTPErr({
message: 'Microsoft auth is not enabled', message: 'Microsoft auth is not enabled',
statusCode: 404, statusCode: 404,
}); });
return true; return super.canActivate(context);
} }
getAuthenticateOptions(context: ExecutionContext) { getAuthenticateOptions(context: ExecutionContext) {