livekit
This commit is contained in:
28
apps/mediasoup-server/modules/socketJWTmiddleware.ts
Normal file
28
apps/mediasoup-server/modules/socketJWTmiddleware.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { ExtendedError, Server, Socket } from "socket.io";
|
||||
import { prisma } from "@repo/db";
|
||||
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 { uid } = socket.handshake.auth;
|
||||
if (!uid) return new Error("Authentication error");
|
||||
/* const token = socket.handshake.auth?.token;
|
||||
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
|
||||
const user = await prisma.user.findUniqueOrThrow({
|
||||
where: { id: uid },
|
||||
});
|
||||
|
||||
socket.data.user = user;
|
||||
|
||||
next();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
next(new Error("Authentication error"));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user