Obtaining an authenticated user's id with React

Hello, I am attempting to use an authenticated user’s id for verification purposes for something outside of Auth0, but haven’t been able to obtain the data.

I am able to access the user’s email through the following and access it through the state, but I am unable to access the user’s id. Am I missing something?

if (isAuthenticated) {
setMail(user.email)
console.log(user.user_id)
}

Hi @vedaantv,

Welcome to the Community!

When you use const { user } = useAuth0(); the user object is the same as the decoded ID Token payload. Here is an example ID Token: ID Token Structure

The user’s ID is the sub claim. You can log it like this: console.log(user.sub)

Thank you, this worked!

1 Like