Auth0 Home Blog Docs

Ensure and Access Unique User ID and Username Regardless of Database or Social Connection

username
user-id

#1

I’ve been scouring the Auth0 documentation for the last day or so and I just can’t seem to understand how to accomplish a very standard auth scenario. Here’s what I want to do:

  • When a potential customer creates an account, let them use either the UN/PW database option or a number of social providers.
  • Ensure that regardless of how they create their account, they have a user id that I can use as a primary key in my database to link their app-specific data. The id should remain the same for this user even if they link additional social accounts later. It shouldn’t matter whether they started with a UN/PW or with a social provider.
  • Make them choose a Username and ensure that the Username is unique across my app, regardless of whether they sing up with the UN/PW database option or a social provider.

The application architecture around this is a SPA client with a Web API backend. So, I need the following to work after account creation and login:

  • Be able to display the Username and profile image of the user in the client. (This I’ve seen how to do.)
  • Be able to extract the username and user id from the access token on the server for each request.

After going through docs, jumping back and forth all over the place to just see how the standard flows would work for a setup like this, it’s just not clear that the user id is something unique or suitable as a primary key in my data. If it isn’t, then how am I supposed to do anything with the user? It’s also not clear if there’s a way to ensure the username is provided for my app for social signups. Finally, it’s not clear how to access any of this data on the server from the token.

I was hoping to get this up and running in just a few minutes, but I got stuck rummage around in docs for hours trying understand if this basic scenario is even possible. Can anyone assist?


#2

I am also struggling to find a way to ensure a that the userid remains the same. There seems to be a number of issues involved.

As far as I can tell when you use the account linking rule it replaces the primary user id which means your database id is incorrect.

Also there seems to be little information on how best to structure your database schema to support this.


#3

Hey Rob,

Have you seen https://github.com/auth0/rules/issues/71


#4

I am also struggling to find a way to ensure a that the userid remains the same. There seems to be a number of issues involved.

As far as I can tell when you use the account linking rule it replaces the primary user id which means your database id is incorrect.

Also there seems to be little information on how best to structure your database schema to support this.


#5

Hey Rob,

Have you seen https://github.com/auth0/rules/issues/71


#6