import { ConfigIntelServer } from '@dripjs/types' ; import { CanActivate , ExecutionContext , Injectable } from '@nestjs/common' ; @ Injectable ( ) export class AuthGuard implements CanActivate { canActivate ( context ) { try { const client = context . switchToWs ( ) . getClient ( ) ; const username = client . handshake . headers [ 'username' ] ; const password = client . handshake . headers [ 'password' ] ; if ( ! username || ! password ) { throw new Error ( 'Auth info not found.' ) ; } const config = require ( 'config' ) . container . intelService ; if ( config . username !== username || config . password !== password ) { throw new Error ( 'Authentication failed.' ) ; } } catch ( e ) { return false ; } return true ; } }