Schafkopf-Server/Public/storage.js
Christoph Hagen 213bb1c179 Extract login pages to own files
Fix api

Remove login window
2022-10-12 19:56:25 +02:00

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)
}