From a9ec6659117fd3f8e6f6f478d5c1011b9e66df2d Mon Sep 17 00:00:00 2001 From: io53 Date: Wed, 6 Nov 2024 23:45:16 +0200 Subject: [PATCH] store new user email if it has changed #456 --- src/NetworkApi.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/NetworkApi.js b/src/NetworkApi.js index f0c6b56..f144c17 100644 --- a/src/NetworkApi.js +++ b/src/NetworkApi.js @@ -24,7 +24,11 @@ function sortSensors(sensors) { function checkStatusCode(response) { let status = response?.status - if (status === 401) logout() + if (status === 401) { + logout() + return false + } + return true } class NetworkApi { @@ -86,11 +90,18 @@ class NetworkApi { user(success, fail) { if (!this.options) return fail("Not signed in") fetch(this.url + "/user", this.options).then(function (response) { - checkStatusCode(response) + if (!checkStatusCode(response)) return return response.json(); }) .then(response => { if (response.data && response.data.sensors.length > 0) { + let email = response.data.email + let userObj = this.getUser() + if (userObj && userObj.email !== email) { + console.log("email changed") + userObj.email = email + this.setUser(userObj) + } response.data.sensors = sortSensors(response.data.sensors) } success(response)