From ada60c18fa8d9c3116408474b0e606f46018c53f Mon Sep 17 00:00:00 2001 From: Oliver Klemenz Date: Fri, 10 Jan 2025 17:35:47 +0100 Subject: [PATCH] Auth --- src/socket/base.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/socket/base.js b/src/socket/base.js index bc4ce2f..162536f 100644 --- a/src/socket/base.js +++ b/src/socket/base.js @@ -222,6 +222,7 @@ class SocketServer { */ middlewares() { const base = this; + function wrapMiddleware(middleware) { return (socket, next) => { let nextCalled = false; @@ -366,9 +367,13 @@ class SocketServer { /** * Enforce that socket request is authenticated (no anonymous) * @param {Object} socket Server socket + * @param {Function} next Call next */ enforceAuth(socket, next) { - if (cds.context?.user?._is_anonymous || (socket.request.isAuthenticated && !socket.request.isAuthenticated())) { + if ( + cds.context?.user?._is_anonymous || + (typeof socket.request?.isAuthenticated === "function" && !socket.request?.isAuthenticated()) + ) { const err = new Error("401"); err.code = 4401; return next(err);