- if (this.state.user.id > 0)
- {
- ajax("/whoami", "GET", res => {
- this.state.user.email = res.email;
- this.state.user.notify = res.notify;
- });
- }
- this.state.conn = new WebSocket(
- params.socketUrl + "/?sid=" + mysid + "&page=" + page);
+ // 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;
+ });