mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-17 05:13:32 +00:00
feat: add auth to server requests
This commit is contained in:
committed by
Carlos Valente
parent
ce8d534953
commit
7fe5223af9
@@ -25,6 +25,7 @@ import { eventStore } from '../stores/EventStore.js';
|
||||
import { logger } from '../classes/Logger.js';
|
||||
import { dispatchFromAdapter } from '../api-integration/integration.controller.js';
|
||||
import { generateId } from 'ontime-utils';
|
||||
import { authenticateSocket } from '../middleware/authenticate.js';
|
||||
|
||||
let instance: SocketServer | null = null;
|
||||
|
||||
@@ -51,7 +52,12 @@ export class SocketServer implements IAdapter {
|
||||
this.shouldShowWelcome = showWelcome;
|
||||
this.wss = new WebSocketServer({ path: `${prefix}/ws`, server, maxPayload: this.MAX_PAYLOAD });
|
||||
|
||||
this.wss.on('connection', (ws) => {
|
||||
this.wss.on('connection', (ws, req) => {
|
||||
authenticateSocket(ws, req, (error) => {
|
||||
if (error) {
|
||||
ws.close(1008, 'Unauthorized');
|
||||
}
|
||||
});
|
||||
const clientId = generateId();
|
||||
|
||||
this.clients.set(clientId, {
|
||||
|
||||
Reference in New Issue
Block a user