Refactor SSE Endpoint with Enhanced Token Validation and Client Management

- Replaced direct token comparison with TokenManager validation
- Implemented robust SSE client connection and event subscription workflow
- Added detailed client authentication and connection status reporting
- Improved SSE endpoint with flexible event, entity, and domain subscription
- Enhanced error handling and client disconnect management
This commit is contained in:
jango-blockchained
2025-02-01 07:50:54 +01:00
parent d3da46d5d5
commit 431a68d690
2 changed files with 58 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
import { EventEmitter } from 'events';
import { HassEntity, HassEvent, StateChangedEvent } from '../types/hass.js';
import { TokenManager } from '../security/index.js';
interface RateLimit {
count: number;
@@ -264,8 +265,7 @@ export class SSEManager extends EventEmitter {
private validateToken(token?: string): boolean {
if (!token) return false;
// Compare with HASS_TOKEN from environment
return token === process.env.HASS_TOKEN;
return TokenManager.validateToken(token);
}
// Utility methods