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
diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js
index d64c730..7a0c5ba 100644
--- a/src/store/modules/Authentication/AuthenticanStore.js
+++ b/src/store/modules/Authentication/AuthenticanStore.js
@@ -10,7 +10,8 @@
},
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 409b168..965c32c 100644
--- a/src/store/plugins/WebSocketPlugin.js
+++ b/src/store/plugins/WebSocketPlugin.js
@@ -18,7 +18,8 @@
};
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));
};