Skip to content

Commit

Permalink
Auth
Browse files Browse the repository at this point in the history
  • Loading branch information
oklemenz2 committed Jan 10, 2025
1 parent 72854b5 commit ada60c1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/socket/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class SocketServer {
*/
middlewares() {
const base = this;

function wrapMiddleware(middleware) {
return (socket, next) => {
let nextCalled = false;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ada60c1

Please sign in to comment.