簡體   English   中英

如何從命令行設置 firebase 自定義聲明?

[英]How to set up firebase custom claims from command line?

人們以前看過類似的問題,但我能找到的最新的是 2018 年。

如何使用終端在 firebase 中設置自定義聲明?

我想執行一個腳本,將具有指定電子郵件的用戶設置為管理員。

腳本是:

const admin = require('firebase-admin');
admin.initializeApp()

const adminEmails = [
    "test1@test.com",
    "test2@test.com",
    "test3@test.com"
]

for (let adminEmail of adminEmails) {
    admin.auth().getUserByEmail(adminEmail)
    .then(function(userRecord) {
      // See the UserRecord reference doc for the contents of userRecord.
      console.log('Successfully fetched user data:', userRecord.toJSON());
      admin.auth().setCustomUserClaims(userRecord.uid, {admin: true}).then(() => {
          // The new custom claims will propagate to the user's ID token the
          // next time a new one is issued.
        });
    })
    .catch(function(error) {
     console.log('Error fetching user data:', error);
    });
}

當我使用節點運行此程序時,我得到無效的憑據 - 我如何從命令行進行身份驗證,是否可以運行創建這樣的自定義聲明的腳本?

該錯誤消息表明您需要傳遞一個帶有服務帳戶憑據的 object 來initializeApp()以配置管理員 SDK,或設置GOOGLE_APPLICATION_CREDENTIALS env var,如文檔中所述。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM