Skip to content

Commit

Permalink
🔒 Discard the playerToken if it is about to expire
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth committed Mar 11, 2017
1 parent c5d1cbf commit 5767242
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/online/scoreboard-system/OnlineService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export class OnlineService {
redirectUri: window.location.href,
responseType: 'token id_token'
})
this._scoreboardClient = createScoreboardClient({ server, auth })
this._scoreboardClient = createScoreboardClient({
server,
auth,
log: () => { }
})
this._storagePrefix = storagePrefix
this._updateUserFromStorage()
this._renewPlayerToken()
Expand All @@ -23,7 +27,14 @@ export class OnlineService {
const loadUser = (text) => {
if (!text) return null
try {
return JSON.parse(text)
const data = JSON.parse(text)
const playerToken = data.playerToken
const playerTokenExpires = JSON.parse(atob(playerToken.split('.')[1])).exp * 1000
if (Date.now() > playerTokenExpires - 86400e3) {
console.warn('Authentication token is about to expire, skipping!')
return null
}
return data
} catch (e) {
return null
}
Expand Down

0 comments on commit 5767242

Please sign in to comment.