【问题标题】:Firebase cloud function return error Error: There is no user record corresponding to the provided identifierFirebase云函数返回错误错误:没有与提供的标识符对应的用户记录
【发布时间】:2019-06-02 19:23:36
【问题描述】:

我想在触发函数中设置CustomUserClaims,但是我得到了这个错误

这是我的一段代码:

   exports.onCreateCompaniesByUserFunction = 

  functions.firestore.document('/companiesByUser/{userId}').onWrite((change,  context) => {
        const  { userId } = context.params;

        const document = change.after.exists ? change.after.data() : null;

        console.log('document',document)
        let owner =  []
        let employee = []
         let editor = []

    Object.keys(document).map(key => {
      if (document[key] == 'affiliate' || document[key] == 'employee') {
        employee.push( key )
      } else if (document[key] == 'owner') {
        owner.push( key )
      } else if (document[key] == 'editor') {
        editor.push( key )
      }
    });


    console.log('owner',owner)
    console.log('employee',employee)
    console.log('editor',editor)
    console.log('before the claims 2',userId)
    return admin.auth().setCustomUserClaims(userId, {employee, owner, editor})
    .then(() => {

      console.log('claim set successfully!');
      return true;



    })
    .catch((error) => {
      console.log('in error',error);
    });

});

根据那个UserId是存在的,但是在日志中,就是说没有对应的用户。

【问题讨论】:

  • 您已经验证 Firebase 身份验证仪表板中确实有一个用户,其 id 与 userId 相同?因为错误信息说没有。
  • 是的......确实,在 Firebase 身份验证仪表板中,我可以找到相同的用户 ID。这就是为什么它是有线的。
  • 你可以有多个项目。您可能正在将服务帐户凭据用于其他项目。
  • 是的,功能云功能的配置不同,指向不同的数据库

标签: javascript node.js firebase firebase-authentication google-cloud-firestore


【解决方案1】:

尝试点击 Firebase 主屏幕右侧的“身份验证”。然后,点击“开始”。

启用您正在使用的所有登录方法。

这解决了我的问题。

【讨论】:

    【解决方案2】:

    您确定您使用的是正确的数据库配置吗?也许您忘记将连接从登台更改为生产。你应该仔细检查你的数据库配置(通常在functions/index.js):

    admin.initializeApp({
      credential: YOUR_CREDENTIAL_FILE,
      databaseURL: 'YOUR_DATABSE_URL',
      ...
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-18
      • 2019-08-21
      • 1970-01-01
      • 2018-03-22
      • 2021-04-20
      • 2019-09-03
      • 1970-01-01
      相关资源
      最近更新 更多