我的Firebase客户端应用与自定义后端服务器通信,因此我需要将每个HTTPS请求的ID
令牌发送到我的服务器。来自参考,
Should only be set to true if the token is invalidated out of band
forcerefresh
布尔设置为true
? forcerefresh
为false)。 (当它作为任务返回时,我应该将它存储在我的本地缓存中,这样我就不必添加任何任务监听器并且可以在同一个线程中处理请求)修改 现在谷歌提供了新的api,如果它已过期,它将自动刷新令牌。
getIdToken(forceRefresh) returns firebase.Promise containing string
来自Google文档
如果当前令牌尚未过期,则返回当前令牌,否则将刷新令牌并返回新令牌
答案 0 :(得分:8)
In general, set forceRefresh to false. That is the recommended behavior. However, that depends on what your are doing. You may want to ensure your token is up to date at all times and available synchronously. To do so you have to refresh a couple of minutes before the the token expires. If you call getToken(false), you will get back the cached token which is about to expire which is not desired. In that case, you force a refresh and update the token. By doing so, you ensure you have an unexpired token at all times synchronously.
答案 1 :(得分:3)
除非您想强制刷新,否则将其设置为false。如果将其设置为false,Firebase将获取缓存的令牌(如果尚未过期)或刷新令牌并将其返回(如果已过期)。
https://firebase.google.com/docs/reference/js/firebase.User#getToken