javascript - Firebase:自定义声明要求我的用户注销并登录才能生效?

标签 javascript firebase firebase-authentication firebase-admin

分配自定义声明时,客户端中的用户必须先注销并登录,然后声明才会显示在其帐户上。我今天花了一整天的时间试图找出为什么我的声明没有生效,结果用户必须重新登录才能让声明无缘无故地显示 LOL rip 我一天中的 5 个小时。我可以添加什么内容来刷新用户信息而无需重新登录吗?

最佳答案

可以通过调用currentUser.getIdToken(true)强制刷新自定义声明。

来自文档...

Propagate custom claims to the client

After new claims are modified on a user via the Admin SDK, they are propagated to an authenticated user on the client side via the ID token in the following ways:

  • A user signs in or re-authenticates after the custom claims are modified. The ID token issued as a result will contain the latest claims.
  • An existing user session gets its ID token refreshed after an older token expires.
  • An ID token is force refreshed by calling currentUser.getIdToken(true).

关于javascript - Firebase:自定义声明要求我的用户注销并登录才能生效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60272993/

相关文章:

Firebase/Flutter : reload() not refreshing user. isEmailVerified

javascript - 为什么我的容器组件不能正确接收 Async Await 的结果?

swift - 这两段代码没有按顺序执行?

php - 如何通过 Rest Api 使用 Firebase Auth Admin SDK?

javascript - 使用 preload.js 和 create.js 加载图像?

javascript - c能否在我的脚本执行之前触发 DOM 事件?

javascript - 如何在位置 : n in div 插入新元素

javascript - 使用 jquery 在 bootstrap 中获取选定表行的值

AngularJS + Firebase : Uncaught Document body has not initialized. 等待文档准备好后初始化 Firebase

firebase - Vuexfire 将 Firestore 集合绑定(bind)到对象而不是列表