fix authentication fail after login

This commit is contained in:
hippoz 2021-03-27 07:31:31 +02:00
parent 6111d1dfa3
commit c5210b40c3
No known key found for this signature in database
GPG key ID: 7C52899193467641
3 changed files with 6 additions and 10 deletions

View file

@ -1,15 +1,13 @@
import Logger from '../Util/Logger'; import Logger from '../Util/Logger';
import gateway from "./Gateway/globalGatewayConnection"; import gateway from "./Gateway/globalGatewayConnection";
import token from "./TokenManager";
const { log: authLog } = Logger([ 'Authenticator' ]); const { log: authLog } = Logger([ 'Authenticator' ]);
const Authenticator = { const Authenticator = {
getToken: function() {
return localStorage.getItem("token");
},
login: async function() { login: async function() {
authLog('Logging in through gateway...'); authLog('Logging in through gateway...');
return gateway.connect(); return gateway.connect(token.getToken());
} }
}; };

View file

@ -45,13 +45,12 @@ const getOpcodeByName = (name) => {
class GatewayConnection { class GatewayConnection {
constructor(token, gatewayUrl) { constructor(gatewayUrl) {
this.token = token;
this.gatewayUrl = gatewayUrl; this.gatewayUrl = gatewayUrl;
} }
} }
GatewayConnection.prototype.connect = function() { GatewayConnection.prototype.connect = function(token) {
this.ws = new WebSocket(this.gatewayUrl); this.ws = new WebSocket(this.gatewayUrl);
this.handshakeCompleted = false; this.handshakeCompleted = false;
@ -73,7 +72,7 @@ GatewayConnection.prototype.connect = function() {
// Got HELLO from server, send YOO as soon as possible // Got HELLO from server, send YOO as soon as possible
logGateway("Got HELLO", packet.data); logGateway("Got HELLO", packet.data);
logGateway("Sending YOO"); logGateway("Sending YOO");
this.ws.send(this.packet("YOO", { token: this.token })); this.ws.send(this.packet("YOO", { token }));
break; break;
} }
case "YOO_ACK": { case "YOO_ACK": {

View file

@ -1,9 +1,8 @@
import GatewayConnection from './GatewayConnection'; import GatewayConnection from './GatewayConnection';
import config from '../../Config'; import config from '../../Config';
import token from '../TokenManager';
import store from '../../Global/store'; import store from '../../Global/store';
const globalGatewayConnection = new GatewayConnection(token.getToken(), config.gatewayUrl); const globalGatewayConnection = new GatewayConnection(config.gatewayUrl);
globalGatewayConnection.onopen = (sessionData) => { globalGatewayConnection.onopen = (sessionData) => {
store.dispatch({ type: 'gateway/connectionstatus', gateway: { isConnected: true } }); store.dispatch({ type: 'gateway/connectionstatus', gateway: { isConnected: true } });