continue dispatch-server

This commit is contained in:
PxlLoewe
2025-03-14 00:18:06 -07:00
parent ec335ce489
commit 05b7d0fd39
14 changed files with 179 additions and 22 deletions

View File

@@ -0,0 +1,28 @@
import { ExtendedError, Server, Socket } from "socket.io";
import jwt from "jsonwebtoken";
import { pubClient } from "modules/redis";
if (!process.env.DISPATCH_APP_TOKEN)
throw new Error("DISPATCH_APP_TOKEN is not defined");
export const jwtMiddleware = async (
socket: Socket,
next: (err?: ExtendedError) => void,
) => {
try {
const token = socket.handshake.auth?.token;
console.log(socket.handshake);
if (!token) return new Error("Authentication error");
const decoded = jwt.verify(token, process.env.DISPATCH_APP_TOKEN!);
// socket.data.userId = decoded.; // User ID lokal speichern
// Prüfen, ob der Nutzer ein Disponent ist
const userId: any = decoded;
socket.data.user = decoded; // Lokal speichern
// In Redis speichern: Key = 'connected_dispatchers', Feld = socket.id, Wert = JSON-String des Users
} catch (err) {
console.error(err);
next(new Error("Authentication error"));
}
};