213bb1c179
Fix api Remove login window
39 lines
1009 B
JavaScript
39 lines
1009 B
JavaScript
// Local storage element identifiers
|
|
const localStorageTokenId = "token";
|
|
const localStoragePlayerName = "name";
|
|
|
|
// Can prevent loading of session token, to allow multiple players per browser
|
|
const debugMode = false
|
|
|
|
/*
|
|
* Store the player name and session token in local storage.
|
|
* Parameter name: The user name of the player
|
|
* Parameter token: The session token for the player session
|
|
*/
|
|
function storePlayerNameAndToken(name, token) {
|
|
localStorage.setItem(localStoragePlayerName, name);
|
|
localStorage.setItem(localStorageTokenId, token);
|
|
}
|
|
|
|
/*
|
|
* Get the last session token from local storage.
|
|
*/
|
|
function loadSessionToken() {
|
|
if (debugMode) {
|
|
return debugSessionToken
|
|
}
|
|
return localStorage.getItem(localStorageTokenId)
|
|
}
|
|
|
|
function storeSessionToken(token) {
|
|
if (debugMode) {
|
|
debugSessionToken = token
|
|
return
|
|
}
|
|
localStorage.setItem(localStorageTokenId, token)
|
|
}
|
|
|
|
function deleteSessionToken() {
|
|
localStorage.removeItem(localStorageTokenId)
|
|
}
|