- // TODO: if there is a socket ID in localStorage, it means a live game was interrupted (and should resume)
- const mysid = localStorage["mysid"] || getRandString();
- this.state.conn = new WebSocket(params.socketUrl + "/?sid=" + mysid);
+ // Slow verification through the server:
+ // NOTE: still superficial identity usurpation possible, but difficult.
+ fetch(
+ params.serverUrl + "/whoami",
+ {
+ method: "GET",
+ headers: headers,
+ credentials: params.credentials
+ }
+ )
+ .then(res => res.json())
+ .then(json => {
+ this.state.user.id = json.id;
+ const storedId = localStorage.getItem("myid");
+ if (json.id > 0 && !storedId)
+ // User cleared localStorage
+ localStorage.setItem("myid", json.id);
+ else if (json.id == 0 && !!storedId)
+ // User cleared cookie
+ localStorage.removeItem("myid");
+ this.state.user.name = json.name;
+ const storedName = localStorage.getItem("myname");
+ if (!!json.name && !storedName)
+ // User cleared localStorage
+ localStorage.setItem("myname", json.name);
+ else if (!json.name && !!storedName)
+ // User cleared cookie
+ localStorage.removeItem("myname");
+ this.state.user.email = json.email;
+ this.state.user.notify = json.notify;
+ });