# Extract user\_id from token in backend

**URL:** <https://community.auth0.com/t/extract-user-id-from-token-in-backend/55614>\
**Category:** Get Help\
**Tags:** jwt, auth0\
**Created:** [January 2, 2021, 12:52pm UTC](https://community.auth0.com/t/extract-user-id-from-token-in-backend/55614 "2021-01-02T12:52:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yannick.koitzsch](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yannick.koitzsch/32/26627_2.png) [@yannick.koitzsch](https://community.auth0.com/u/yannick.koitzsch)\
**Post date:** [January 2, 2021, 12:52pm UTC](https://community.auth0.com/t/extract-user-id-from-token-in-backend/55614/1 "2021-01-02T12:52:28Z")

</div>

Hello,  
I have an angular application with a nodejs backend. I followed the [official angular-auth0](https://auth0.com/docs/quickstart/spa/angular/01-login) 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

---

<div class="post-metadata">

**Author:** ![mathiasconradt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mathiasconradt/32/12758_2.png) [@mathiasconradt](https://community.auth0.com/u/mathiasconradt)\
**Post date:** [January 3, 2021, 9:35am UTC](https://community.auth0.com/t/extract-user-id-from-token-in-backend/55614/2 "2021-01-03T09:35:31Z")

</div>

The `sub` claim is the [OAuth2 standard claim name](https://tools.ietf.org/html/rfc7519#section-4.1.2), 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.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 4, 2021, 10:15am UTC](https://community.auth0.com/t/extract-user-id-from-token-in-backend/55614/3 "2021-01-04T10:15:32Z")

</div>

Thanks for contributing on this one Mathias!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 19, 2021, 10:15am UTC](https://community.auth0.com/t/extract-user-id-from-token-in-backend/55614/4 "2021-01-19T10:15:32Z")

</div>

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