Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user's id from auth0 in React

I recently implemented user authentication in my react web app using Auth0. And I need to retrieve some information from user object. I did this so far:

cost { user, isAuthenticated } = useAuth0();
<p>{user.name}</p>

But I also want to get user's id, so I can reference them later in my backend. So I did this:

const { user, isAuthenticated } = useAuth0();
<p>{user.user_id}</p>

And when I go to the website I get undefined instead of the user's id.

Is it happening because I use dev-keys for my social connections, or maybe it has to be done differently?

like image 412
Jakub Klimek Avatar asked Oct 22 '25 04:10

Jakub Klimek


1 Answers

Not sure if you are still searching for this problem, however I had a similar problem and found this as a solution:

const { user, isAuthenticated } = useAuth0();
<p>{user.sub}</p>

source: https://community.auth0.com/t/how-to-get-user-id-of-a-user-after-login-in-react-hook-useauth0/53309

like image 174
DeBelg Avatar answered Oct 24 '25 18:10

DeBelg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!