title: Adding a custom claim to the onCreate user firebase cloud function
body: <p>I am trying on a firebase cloud function to add some custom claims when a new user is created. As the custom claims I need to add a User role to the created user</p>
  
  <p>I have tried on some tutorials where user role is added after the user created. <a href="https://www.youtube.com/watch?v=4wa3CMK4E2Y" rel="nofollow noreferrer">https://www.youtube.com/watch?v=4wa3CMK4E2Y</a>. But I thought of adding custom claims on the creation of the user and returning with the response</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp(functions.config().firebase);
  
  exports.addDefaultUserRole = functions.auth.user().onCreate((user) =&gt; {
  
      let uid = user.uid;
  
      //add custom claims
      return admin.auth().setCustomUserClaims(uid,{
          isAdmin: true,
  
      });
  
  
  });
  </code></pre>
  
  <p>Even the above code get executed in firebase, nothing happened and claims were not received in the response. Is it not a good practice to add custom claims on User creation? What will be the reason for not attaching the custom claims with the above code</p>