Firebase cloud function return error Error: There is no user record corresponding to the provided identifier

Viewed 2766

I want to setCustomUserClaims in trigger function but then I get this error

enter image description here

This is my piece of code:

   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);
    });

});

According to that UserId is exist but in the logs, it is saying that There is no user corresponding.

2 Answers

Try clicking on "Authentication" on the right of the Firebase home screen. Then, click "Get Started".

Enable all of the sign-in methods you're using.

This solved the problem for me.

Are you sure you are using the correct database configuration? Maybe you forgot to change your connection from staging to production. You should double check your database configuration (Usually in functions/index.js):

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