mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-27 16:27:50 +01:00
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { globals } from '../config/globals.js';
|
|
|
|
/*
|
|
we will use sessionStorage during local development to aid in testing, vs. localStorage for production.
|
|
sessionStorage does not persist across tabs, allowing developers to join a game as different players from different windows.
|
|
*/
|
|
export const UserUtility = {
|
|
|
|
setAnonymousUserId (id, environment) {
|
|
if (environment === globals.ENVIRONMENT.LOCAL) {
|
|
sessionStorage.setItem(globals.PLAYER_ID_COOKIE_KEY, id);
|
|
} else {
|
|
localStorage.setItem(globals.PLAYER_ID_COOKIE_KEY, id);
|
|
}
|
|
},
|
|
|
|
validateAnonUserSignature (environment) {
|
|
let userSig;
|
|
if (environment === globals.ENVIRONMENT.LOCAL) {
|
|
userSig = sessionStorage.getItem(globals.PLAYER_ID_COOKIE_KEY);
|
|
} else {
|
|
userSig = localStorage.getItem(globals.PLAYER_ID_COOKIE_KEY);
|
|
}
|
|
return (
|
|
userSig
|
|
&& typeof userSig === 'string'
|
|
&& /^[a-zA-Z0-9]+$/.test(userSig)
|
|
&& userSig.length === globals.USER_SIGNATURE_LENGTH
|
|
)
|
|
? userSig
|
|
: false;
|
|
}
|
|
|
|
};
|