Get user id on login

Hello, im new to this service. i followed the tutorial to implement a basic login/register popup and it works fine, but i need to get the users unique id, is it possible? I need it to get each users data from the db

Hey there @jezerro welcome to the community!

Are you just looking for the user’s ID as it is in Auth0? If that’s the case I recommend looking into Actions and in particular a Post Login Action wherein you can access the user_id with event.user.user_id as outlined here.

Let us know!

1 Like

hey tyf, thanks for the quick reply! user_id is indeed what i need, but im not sure how i send it to the client. i created an action with a onExecutePostLogin() handler that just returns it, is that the correct way? Also, is there a specific handler on the client side i must use? Thanks!

No problem, happy to help where I can!

How exactly are you logging users in? Are you using an OAuth/OIDC flow via an Auth0 SDK? The user_id is available as the sub claim in an ID Token if you are indeed using a flow that results in one. Alternatively, you could get the sub claim from the /userinfo endpoint using the user’s access token. This can all be done outside of an action entirely which might be a more straightforward approach.

From within an action, you might want to look at using an external library such as axios (or any publicly available npm package) to communicate with your service.

1 Like

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