Extract user_id from token in backend

Hello,
I have an angular application with a nodejs backend. I followed the official angular-auth0 tutorial and it worked as expected.
I also created an API to secure some backend routes but now I am struggling to extract the user_id from the token passed in the request header from the frontend.

I need the user_id to reference it in my database. I use the jwt-decode library to decode the token and then use the “sub” property instead. Is this a good workaround? I prefer to use the user_id.

Any advice are appreciated. Thank you

The sub claim is the OAuth2 standard claim name, and it contains the subject = user_id, so yes, that’s fine to use, I therefore wouldn’t even consider it a workaround but a proper way.

1 Like

Thanks for contributing on this one Mathias!

1 Like

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