From 5a8a75edc0787fd4515b832e35c1868182d35d36 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 23 Jun 2022 14:50:00 +0200 Subject: [PATCH] feat(ui): separate the namespace from the server URL This should help prevent people from connecting to the main namespace, when they forget to include the namespace at the end of the server URL. Related: - https://github.com/socketio/socket.io-admin-ui/issues/26 - https://github.com/socketio/socket.io-admin-ui/issues/42 --- ui/src/App.vue | 9 ++++-- ui/src/components/ConnectionModal.vue | 45 ++++++++++++++++++++------- ui/src/locales/en.json | 4 ++- ui/src/locales/fr.json | 7 ++++- ui/src/store/modules/connection.js | 13 ++++++-- 5 files changed, 60 insertions(+), 18 deletions(-) diff --git a/ui/src/App.vue b/ui/src/App.vue index 2824e16..d0ad542 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -17,6 +17,7 @@ :initial-server-url="serverUrl" :initial-ws-only="wsOnly" :initial-path="path" + :initial-namespace="namespace" :initial-parser="parser" :is-connecting="isConnecting" :error="connectionError" @@ -70,6 +71,7 @@ export default { serverUrl: (state) => state.connection.serverUrl, wsOnly: (state) => state.connection.wsOnly, path: (state) => state.connection.path, + namespace: (state) => state.connection.namespace, parser: (state) => state.connection.parser, backgroundColor: (state) => state.config.darkTheme ? "" : "grey lighten-5", @@ -92,7 +94,7 @@ export default { }, methods: { - tryConnect(serverUrl, auth, wsOnly, path, parser) { + tryConnect(serverUrl, namespace, auth, wsOnly, path, parser) { this.isConnecting = true; if (SocketHolder.socket) { SocketHolder.socket.disconnect(); @@ -100,7 +102,7 @@ export default { SocketHolder.socket.off("connect_error"); SocketHolder.socket.off("disconnect"); } - const socket = io(serverUrl, { + const socket = io(serverUrl + namespace, { forceNew: true, reconnection: false, withCredentials: true, // needed for cookie-based sticky-sessions @@ -119,6 +121,7 @@ export default { serverUrl, wsOnly, path, + namespace, parser, }); SocketHolder.socket = socket; @@ -210,6 +213,7 @@ export default { onSubmit(form) { this.tryConnect( form.serverUrl, + form.namespace, { username: form.username, password: form.password, @@ -231,6 +235,7 @@ export default { const sessionId = this.$store.state.connection.sessionId; this.tryConnect( this.serverUrl, + this.namespace, { sessionId, }, diff --git a/ui/src/components/ConnectionModal.vue b/ui/src/components/ConnectionModal.vue index 80adb04..9b0667f 100644 --- a/ui/src/components/ConnectionModal.vue +++ b/ui/src/components/ConnectionModal.vue @@ -12,7 +12,7 @@ - + +
+ - + + + + + +
+