Skip to content

Commit

Permalink
fix token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
hornmo committed Oct 14, 2024
1 parent 6f75df9 commit 6823b7c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
this.globalSearchItems.push(res)
} else {
console.log('Not Adding item..')
log.debug('Not Adding item..')
}
})
}
Expand Down Expand Up @@ -493,7 +493,7 @@
this.groups = result.data.data.curatoryGroups
console.log("Loading groups!")
log.debug("Loading groups!")
if (this.groups.length > 0) {
this.activeGroup = accountModel.activeGroup() || this.groups[0]
Expand Down
7 changes: 5 additions & 2 deletions src/shared/models/token-model/token-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const api = (browserStorage) => {

return {
isPersistent () {
return localStorage.get(PERSISTENCE_KEY, true) === "true"
return localStorage.get(PERSISTENCE_KEY, true) === true
},
removeToken () {
localStorage.remove(TOKEN_KEY)
Expand All @@ -17,11 +17,14 @@ const api = (browserStorage) => {
localStorage.remove(PERSISTENCE_KEY)
},
needsRefresh () {
return !!localStorage.get(EXPIRATION_KEY, true) && !!this.getToken() && !/^\d+$/.test(localStorage.get(EXPIRATION_KEY, true)) && (Date.now() > (parseInt(localStorage.get(EXPIRATION_KEY, true) - 300000)))
return Date.now() > (localStorage.get(EXPIRATION_KEY, true) - 600000)
},
isExpired () {
return !localStorage.get(EXPIRATION_KEY, true) || !/^\d+$/.test(localStorage.get(EXPIRATION_KEY, true)) || (!!this.getToken() && Date.now() > parseInt(localStorage.get(EXPIRATION_KEY, true)))
},
existsToken () {
return !!this.getToken()
},
getToken () {
return localStorage.get(TOKEN_KEY)
},
Expand Down
1 change: 1 addition & 0 deletions src/shared/services/base-services/base-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const api = (http, log, utils, tokenModel, accountModel) => ({
const refresh_resp = await this.refreshAuth()

if (refresh_resp?.status === 200) {
log.debug("Successfully refreshed token ..")
} else {
log.debug("Unable to refresh token .. logging out")
accountModel.default.logout()
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/logger/logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const api = (console, utils) => {
const isProduction = !utils.isDevelopment()
const loggerFunction = level => (...optionalParams) => !isProduction && console[level](...optionalParams)
const loggerFunction = level => (...optionalParams) => !isProduction ? console[level](...optionalParams) : console.info(...optionalParams)

const api = {
LOG_LEVEL: ['log', 'info', 'debug', 'trace', 'warn', 'error', 'assert'],
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const api = {
},

isDevelopment () {
return import.meta.env.NODE_ENV === 'development'
return import.meta.env.DEV
},

asYesNo (value) {
Expand Down
2 changes: 0 additions & 2 deletions src/views/edit/edit-tipp-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,6 @@
instance: this
})
console.log(result)
if (result?.status === 200) {
this.mapRecord(result.data)
} else if (result?.status === 401) {
Expand Down

0 comments on commit 6823b7c

Please sign in to comment.