Field to use for user id

Auth0 will be maintaining my apps users but I need an identifier to go in the application database to connect user date to. I wanted to use user_id but couldn’t figure out how to get it. email is available but I’m wondering if that could change if the user is able to change the email associated with their account.

Which is the best field to keep in the apps database?
How can I get user_id?

I’m using “@auth0/auth0-spa-js”: “^1.1.1”,

Requested scopes are: ‘openid profile email’

It’s the sub claim in the JWT token, or if you use the SPA JS SDK, it’s the sub attribute of the user object you received.

I don’t see ‘sub’.
I’m getting back this

    "email_verified": true,
    "email": "",
    "username": "someusername",
    "updated_at": "2019-07-10T21:59:16.105Z",
    "user_id": "auth0|5a1b61913...",
    "name": "",
    "picture": "",
    "nickname": "someone",
    "identities": [
            "user_id": "6d1a61..",
            "provider": "auth0",
            "connection": "Username-Password-Authentication",
            "isSocial": false
    "created_at": "2019-07-01T19:40:01.385Z",
    "last_ip": "...",
    "last_login": "2019-07-10T21:59:16.105Z",
    "logins_count": 6,
    "blocked_for": [],
    "guardian_authenticators": []

I see user_id there. Don’t know how I missed it before.
Is there significance to the ‘auth0|’ part. Do you recommend keeping that part of the string or parsing it out?

Today I’m getting the below. Haven’t changed the code nor made a configuration change to the Auth0 client. It’s the same console.log statement as yesterday. I’ll move forward using ‘sub’.

  email: ""
  email_verified: true
​  name: ""
​  nickname: "someone"
​  picture: " ... .png"
​  sub: "auth0|5d1c...7"
​  updated_at: "2019-08-08T13:52:06.695Z"

Your code snippet shows two different things, or let’s say, have two different origins. One is the excerpt you probably got from the Auth0 Dashboard > Users > User Profile > Raw JSON.

The latest is an ID Token (JWT) payload.

The user_id in the user profile in the Auth0 dashboard is the equivalent to the sub claim in the JWT ID Token.

In your client application that receives the ID token, this sub claim inside the token payload is what you’re looking for and want to use as a reference.

If you’re using the management API to fetch users, you’d use the user_id attribute instead for any look ups based on that.

Thanks. I did get the first example from the Auth0 Dashboard but had forgotten that. Thank you for the clarification!

1 Like

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