@voltagent/server-core 1.0.29 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4885,21 +4885,37 @@ function setupWebSocketUpgrade(server, wss, pathPrefix = "/ws", auth, logger) {
4885
4885
  }
4886
4886
  user = { id: "console", type: "console-access" };
4887
4887
  } else {
4888
- const token = url.searchParams.get("token");
4889
- if (token) {
4890
- try {
4891
- user = await auth.verifyToken(token);
4892
- } catch (error) {
4893
- logger?.debug("[WebSocket] Token verification failed:", { error });
4894
- socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
4895
- socket.destroy();
4896
- return;
4888
+ const hasConsoleAccess2 = hasWebSocketConsoleAccess(req);
4889
+ if (hasConsoleAccess2) {
4890
+ user = { id: "console", type: "console-access" };
4891
+ } else {
4892
+ const needsAuth = requiresAuth("WS", path2, auth.publicRoutes, auth.defaultPrivate);
4893
+ if (needsAuth) {
4894
+ const token = url.searchParams.get("token");
4895
+ if (token) {
4896
+ try {
4897
+ user = await auth.verifyToken(token);
4898
+ } catch (error) {
4899
+ logger?.debug("[WebSocket] Token verification failed:", { error });
4900
+ socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
4901
+ socket.destroy();
4902
+ return;
4903
+ }
4904
+ } else {
4905
+ logger?.debug("[WebSocket] No token provided for protected WebSocket");
4906
+ socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
4907
+ socket.destroy();
4908
+ return;
4909
+ }
4910
+ } else {
4911
+ const token = url.searchParams.get("token");
4912
+ if (token) {
4913
+ try {
4914
+ user = await auth.verifyToken(token);
4915
+ } catch {
4916
+ }
4917
+ }
4897
4918
  }
4898
- } else if (auth.defaultPrivate) {
4899
- logger?.debug("[WebSocket] No token provided for protected WebSocket");
4900
- socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
4901
- socket.destroy();
4902
- return;
4903
4919
  }
4904
4920
  }
4905
4921
  } catch (error) {