-
-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refresh token question #8
Comments
Also.. not sure when |
After we logged in then refresh page, then this package automatically trying to The problem is..this process is async, so This is the summary
I think we need to call Thanks |
Will have to look into it again. Will update the docs with the workflow/reasoning soon. There is also a related issue with expired tokens not being removed. So it tries to use it giving an auth error on load which is not necessary. Will look into it next week, swamped with some client projects at the moment. |
I did some changes and its work for replacing old token when reload page function _refreshToken (cb) {
cb = cb || function () {}
let _this = this
if (_getToken.call(this) && this.getOption('tokenType') === 'jwt') {
_http.call(this, {
url: this.getOption('tokenUrl'),
method: 'get',
success: (res) => {
_setToken.call(this, res.json()[this.getOption('tokenVar')])
let tokenJSON = _decodeToken(_getToken.call(_this))
let expireTime = _getTokenExpirationDate(tokenJSON).valueOf()
let nowTime = new Date().valueOf()
let offsetTime = this.getOption('tokenTimeoutOffset')
let timeout = expireTime - nowTime - offsetTime
clearTimeout(_tokenRefreshTimeout)
_tokenRefreshTimeout = setTimeout(function () {
_refreshToken.call(_this)
}, timeout)
return cb()
},
error: (res) => {
return cb()
}
})
} else {
return cb()
}
}
...
fetch (cb) {
cb = cb || function () {}
if (!this.loaded) {
_refreshToken.call(this, () => {
this.setLoadedAsTrue(cb)
})
} else {
this.setLoadedAsTrue(cb)
}
},
setLoadedAsTrue (cb) {
if (this.authenticated === null && _getToken.call(this)) {
if (!document.cookie.match(/rememberMe/)) {
_removeToken.call(this)
this.loaded = true
return cb()
}
this.authenticated = false
_fetch.call(this, cb)
} else {
this.loaded = true
return cb()
}
}, |
Hello @ghprod , I think your solution isnt working when you want to /register /login , refresh the page because as the install function is being called on every refresh, function _fetch isnt being triggered so no user is set. Please check your response. |
This has now been reworked a bit in the new v1.0.x-dev version. However by default it will still do a refresh on each init. If you want to disable it you must override the
If you set the token in the header or via param during the user (or any other) request it will automatically get sniffed out and set. So you could put it wherever you like if you wanna go some other route. Or you could also call |
Not sure how this refresh token is supposed to work. When is
_refreshToken
called? And even if it's called at some point it doesn't set anything after http request totokenUrl
. Shouldn't it set the token received by the request.The text was updated successfully, but these errors were encountered: