Retrieving user Id from authorization (Redux/Gatsby/Express/Mongo)


My stack: Gatsby.js/React + Redux + Express/Node.js + MongoDB

I’ve been able to integrate universal sign-on using “auth0-js”. But I’m having trouble figuring out this part of my application.

I need to create user records in my Mongo database and associate those records with the user ID created by auth0. I’ll pass in the user ID to my Express API and look up the correct user record with it.

Currently, I don’t see any tutorials on this type of set up. And I’m not seeing any information about how I can retrieve the user ID from auth0.

What pieces do I need in place for this? And is there a better way to link mongo to auth0.

Hi @jmcewenn, welcome to the Auth0 Community!

It sounds like you might want to use MongoDB as a custom database for your account. Here’s a tutorial we have on using MongoDB Atlas as a custom database that may get you started. We also have some more generic docs on setting up a custom db connection.

Hope that helps!

Sam Julien

Hi Sam,

Thank you for this information.

I will look into and return if I have any questions afterwards.

Thanks again for the great info. I was able to use the custom scripts to create users, etc.

However, I’m facing a new issue that may be related to the recent changes.

Now when I signup using the universal login, I’m getting an error that says, “We’re sorry, there was a problem signing up.” When I check the dev tools, the console reads:

Failed to load resource: the server responded with a status of 400 (Bad Request)
error: “Missing required property: connection”

Signup was working prior to adding the database. Another possible cause may be related to the fact that I deleted the user accounts I created with the universal sign on. I deleted them from the auth0 dashboard.

Interestingly enough, the new user records are making it to my database.

Hmm, it sounds like you’re missing the connection property from the body of your request, which would specify the custom database connection you created. It looks like this forum post is related to what you’re seeing. Check that out and let me know if it solves the problem.

Sam Julien

Hi Sam,

I’m using universal login and I don’t understand where I can set the connection attribute there. Do I need to create a custum UI using the auth API to be able to use a custom database connection?

Hi @jmcewenn, so sorry for the delay – I somehow didn’t see the notification for your response.

Since you’re using auth0-js, you should be able to set the connection parameter in the authorize method (see reference here).