faloker/purify

View on GitHub
api/src/auth/saml-auth.guard.ts

Summary

Maintainability
A
0 mins
Test Coverage
D
66%
/* istanbul ignore file */

import { Injectable, ExecutionContext } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ConfigService } from '@nestjs/config';
import { Observable } from 'rxjs';

@Injectable()
export class SamlAuthGuard extends AuthGuard('saml') {
  constructor(private readonly configService: ConfigService) {
    super();
  }
  canActivate(
    context: ExecutionContext
  ): boolean | Promise<boolean> | Observable<boolean> {
    if (this.configService.get<string>('USE_SAML') === 'true') {
      return super.canActivate(context);
    }

    return false;
  }
}