Get username with auth0 react sdk

So I am trying to get the username from my user object thats retried with the useAuth0 hook.

function (user, context, callback) {
context.idToken['username'] = user.username;
  return callback(null, user, context);
}

That is the rule I am creating on auth0, but I get an error.

How should I then name the property?

I want to access it on the front end to display it on my profile page.

Thanks

Hey @gmwill934, Welcome to the Auth0 Community!

The custom claim you add into your ID token has to be name spaced.
Please find more information and example below:

If you add something like below should work :
const namespace = ‘https://myapp.example.com/’;
context.idToken[namespace +‘username’] = user.username;

Let me know how you go!

Regards,
Sidharth Chaudhary

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.