admin管理员组文章数量:1279178
I'm using web firebase javascript to authenticate by email and password. This process generates a token which I use to verify on my nodejs backend using firebase-admin. Once this token is generated, I store it on the browser local/session storage.
The front end is AngularJs which I intercept the http request to inject the token stored within the browser.
This is working fine, however after a while this token expire. So what would be the best way to refresh this token before it sends to the nodejs api?
Note: should I requet the currentUser.getToken() every request?
I'm using web firebase javascript to authenticate by email and password. This process generates a token which I use to verify on my nodejs backend using firebase-admin. Once this token is generated, I store it on the browser local/session storage.
The front end is AngularJs which I intercept the http request to inject the token stored within the browser.
This is working fine, however after a while this token expire. So what would be the best way to refresh this token before it sends to the nodejs api?
Note: should I requet the currentUser.getToken() every request?
Share Improve this question edited Mar 6, 2017 at 2:02 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges asked Mar 6, 2017 at 1:48 CacoCaco 1311 gold badge2 silver badges4 bronze badges1 Answer
Reset to default 10The currentUser.getIdToken()
only refreshes the token when the current token has expired! So it doesn't create unneeded traffic or requests to Firebase!
firebase.auth().currentUser.getIdToken(true) // here we force a refresh
.then(function(token) {
// ... do stuff!
}).catch(function(error) {
if (error) throw error
});
You'll see that I added true
as an argument to the getIdToken()
function. This forces a refresh!
Here is the Firebase Documentation for the getIdToken()
function.
I hope that helps!
本文标签: javascriptRefresh Firebase TokenStack Overflow
版权声明:本文标题:javascript - Refresh Firebase Token - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741208718a2358671.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论