title: Firebase cloud function return error Error: There is no user record corresponding to the provided identifier
body: <p>I want to setCustomUserClaims in trigger function but then I get this error </p>
  
  <p><a href="https://i.stack.imgur.com/QrLBT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QrLBT.png" alt="enter image description here"></a></p>
  
  <p>This is my piece of code:</p>
  
  <pre><code>   exports.onCreateCompaniesByUserFunction = 
  
    functions.firestore.document('/companiesByUser/{userId}').onWrite((change,  context) =&gt; {
          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 =&gt; {
        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(() =&gt; {
  
        console.log('claim set successfully!');
        return true;
  
  
  
      })
      .catch((error) =&gt; {
        console.log('in error',error);
      });
  
  });
  </code></pre>
  
  <p>According to that UserId is exist but in the logs, it is saying that There is no user corresponding.</p>