dirty localstorage token store
This commit is contained in:
parent
6a719dbb9d
commit
11d07929ba
@ -18,14 +18,19 @@ function createSocket(events) {
|
|||||||
|
|
||||||
// handle account auth within the socket itself
|
// handle account auth within the socket itself
|
||||||
// https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
|
// https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
|
||||||
let account = null;
|
let account;
|
||||||
|
try {
|
||||||
|
account = JSON.parse(localStorage.getItem('account'));
|
||||||
|
} catch (e) {
|
||||||
|
localStorage.removeItem('account');
|
||||||
|
}
|
||||||
|
|
||||||
// -------------
|
// -------------
|
||||||
// Outgoing
|
// Outgoing
|
||||||
// -------------
|
// -------------
|
||||||
function send(msg) {
|
function send(msg) {
|
||||||
console.log('outgoing msg', msg);
|
console.log('outgoing msg', msg);
|
||||||
msg.token = account && account.token;
|
msg.token = account && account.token && account.token;
|
||||||
ws.send(cbor.encode(msg));
|
ws.send(cbor.encode(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +164,7 @@ function createSocket(events) {
|
|||||||
const [struct, login] = res;
|
const [struct, login] = res;
|
||||||
|
|
||||||
account = login;
|
account = login;
|
||||||
|
localStorage.setItem('account', JSON.stringify(login));
|
||||||
events.setAccount(login);
|
events.setAccount(login);
|
||||||
sendAccountCryps();
|
sendAccountCryps();
|
||||||
sendAccountPlayers();
|
sendAccountPlayers();
|
||||||
@ -266,9 +272,10 @@ function createSocket(events) {
|
|||||||
position: 'bottomCenter',
|
position: 'bottomCenter',
|
||||||
});
|
});
|
||||||
|
|
||||||
// if (!account) events.loginPrompt();
|
if (account) {
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
events.setAccount(account);
|
||||||
send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
|
sendAccountPlayers();
|
||||||
|
sendAccountCryps();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user