From c5210b40c3d50844b49b8dd088b65fc0fd014776 Mon Sep 17 00:00:00 2001 From: hippoz Date: Sat, 27 Mar 2021 07:31:31 +0200 Subject: [PATCH] fix authentication fail after login --- bfrontend/src/API/Authenticator.js | 6 ++---- bfrontend/src/API/Gateway/GatewayConnection.js | 7 +++---- bfrontend/src/API/Gateway/globalGatewayConnection.js | 3 +-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/bfrontend/src/API/Authenticator.js b/bfrontend/src/API/Authenticator.js index 2fdc68d..47cf05e 100644 --- a/bfrontend/src/API/Authenticator.js +++ b/bfrontend/src/API/Authenticator.js @@ -1,15 +1,13 @@ import Logger from '../Util/Logger'; import gateway from "./Gateway/globalGatewayConnection"; +import token from "./TokenManager"; const { log: authLog } = Logger([ 'Authenticator' ]); const Authenticator = { - getToken: function() { - return localStorage.getItem("token"); - }, login: async function() { authLog('Logging in through gateway...'); - return gateway.connect(); + return gateway.connect(token.getToken()); } }; diff --git a/bfrontend/src/API/Gateway/GatewayConnection.js b/bfrontend/src/API/Gateway/GatewayConnection.js index 5f10092..853bca7 100644 --- a/bfrontend/src/API/Gateway/GatewayConnection.js +++ b/bfrontend/src/API/Gateway/GatewayConnection.js @@ -45,13 +45,12 @@ const getOpcodeByName = (name) => { class GatewayConnection { - constructor(token, gatewayUrl) { - this.token = token; + constructor(gatewayUrl) { this.gatewayUrl = gatewayUrl; } } -GatewayConnection.prototype.connect = function() { +GatewayConnection.prototype.connect = function(token) { this.ws = new WebSocket(this.gatewayUrl); this.handshakeCompleted = false; @@ -73,7 +72,7 @@ GatewayConnection.prototype.connect = function() { // Got HELLO from server, send YOO as soon as possible logGateway("Got HELLO", packet.data); logGateway("Sending YOO"); - this.ws.send(this.packet("YOO", { token: this.token })); + this.ws.send(this.packet("YOO", { token })); break; } case "YOO_ACK": { diff --git a/bfrontend/src/API/Gateway/globalGatewayConnection.js b/bfrontend/src/API/Gateway/globalGatewayConnection.js index 8a539d6..48fe236 100644 --- a/bfrontend/src/API/Gateway/globalGatewayConnection.js +++ b/bfrontend/src/API/Gateway/globalGatewayConnection.js @@ -1,9 +1,8 @@ import GatewayConnection from './GatewayConnection'; import config from '../../Config'; -import token from '../TokenManager'; import store from '../../Global/store'; -const globalGatewayConnection = new GatewayConnection(token.getToken(), config.gatewayUrl); +const globalGatewayConnection = new GatewayConnection(config.gatewayUrl); globalGatewayConnection.onopen = (sessionData) => { store.dispatch({ type: 'gateway/connectionstatus', gateway: { isConnected: true } });