Skip to content

Commit

Permalink
fix: recovers user from local storage on init
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwicopple committed Oct 12, 2020
1 parent 787bffb commit 4da5a9f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,18 @@ export default class Client {
if (json) {
try {
const data = JSON.parse(json)
const { currentSession, currentUser, expiresAt } = data
const { currentSession, expiresAt } = data

const timeNow = Math.round(Date.now() / 1000)
if (expiresAt < timeNow) {
console.log('Saved session has expired.')
this._removeSession()
} else if (!currentSession || !currentSession.user) {
console.log('Current session is missing data.')
this._removeSession()
} else {
this.currentSession = currentSession
this.currentUser = currentUser
this.currentUser = currentSession.user
// schedule a refresh 60 seconds before token due to expire
setTimeout(this._callRefreshToken, (expiresAt - timeNow - 60) * 1000)
}
Expand Down

0 comments on commit 4da5a9f

Please sign in to comment.