Skip to content

Commit

Permalink
store new user email if it has changed #456
Browse files Browse the repository at this point in the history
  • Loading branch information
io53 committed Nov 6, 2024
1 parent 317d31d commit a9ec665
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/NetworkApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a9ec665

Please sign in to comment.