summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYoshie Muranaka <yoshiemuranaka@gmail.com>2020-05-02 00:19:43 +0300
committerDerick Montague <derick.montague@ibm.com>2020-05-06 18:10:11 +0300
commit23f227dd0d3885c0229a9eff670f1ba21d24d42b (patch)
tree03c17d1e52c73f0b286bd41d5e0f11a8e0253598 /src
parent5c977976d9450b50faeb33ba5bd1b5deaabcc3b5 (diff)
downloadwebui-vue-23f227dd0d3885c0229a9eff670f1ba21d24d42b.tar.xz
Add XSRF token to websocket connection
Resolves HTTP authentication failure when attempting to make a websocket connection. Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com> Change-Id: Ie833f1cd281dd3b7124ac798eb5318b24df0ed8f
Diffstat (limited to 'src')
-rw-r--r--src/store/modules/Authentication/AuthenticanStore.js3
-rw-r--r--src/store/plugins/WebSocketPlugin.js3
2 files changed, 4 insertions, 2 deletions
diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js
index d64c7308..7a0c5ba3 100644
--- a/src/store/modules/Authentication/AuthenticanStore.js
+++ b/src/store/modules/Authentication/AuthenticanStore.js
@@ -10,7 +10,8 @@ const AuthenticationStore = {
},
getters: {
authError: state => state.authError,
- isLoggedIn: state => !!state.cookie
+ isLoggedIn: state => !!state.cookie,
+ token: state => state.cookie
},
mutations: {
authSuccess(state) {
diff --git a/src/store/plugins/WebSocketPlugin.js b/src/store/plugins/WebSocketPlugin.js
index 409b1686..965c32c9 100644
--- a/src/store/plugins/WebSocketPlugin.js
+++ b/src/store/plugins/WebSocketPlugin.js
@@ -18,7 +18,8 @@ const WebSocketPlugin = store => {
};
const initWebSocket = () => {
- ws = new WebSocket(`wss://${window.location.host}/subscribe`);
+ const token = store.getters['authentication/token'];
+ ws = new WebSocket(`wss://${window.location.host}/subscribe`, [token]);
ws.onopen = () => {
ws.send(JSON.stringify(data));
};