wraith/backend/src/auth/ws-auth.guard.ts
Vantz Stockwell 3b9a0118b5 feat: AES-256-GCM encryption service + auth module (JWT, guards, seed)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 17:07:14 -04:00

20 lines
563 B
TypeScript

import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { WsException } from '@nestjs/websockets';
@Injectable()
export class WsAuthGuard {
constructor(private jwt: JwtService) {}
validateClient(client: any): { sub: number; email: string } | null {
try {
const url = new URL(client.url || client._url, 'http://localhost');
const token = url.searchParams.get('token');
if (!token) throw new WsException('No token');
return this.jwt.verify(token);
} catch {
return null;
}
}
}