chore: handled internal server error for missing auth providers

This commit is contained in:
Mir Arif Hasan
2023-07-28 18:26:42 +06:00
parent bdab2bb2d0
commit a72b1feda5
3 changed files with 36 additions and 6 deletions

View File

@@ -1,8 +1,16 @@
import { ExecutionContext, Injectable } from '@nestjs/common';
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { AuthProvider, authProviderCheck, throwHTTPErr } from '../helper';
@Injectable()
export class GithubSSOGuard extends AuthGuard('github') {
export class GithubSSOGuard extends AuthGuard('github') implements CanActivate {
canActivate(context: ExecutionContext): boolean {
if (!authProviderCheck(AuthProvider.GITHUB))
throwHTTPErr({ message: 'GitHub auth is not enabled', statusCode: 404 });
return true;
}
getAuthenticateOptions(context: ExecutionContext) {
const req = context.switchToHttp().getRequest();