Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Retrieving user ID for email/password authentication at signup

I am signing up users using the https://stitch.mongodb.com/api/client/v2.0/app/client-app-id/auth/providers/local-userpass/register endpoint from my server, which takes email & password on a POST request. However, it does not return the user ID. Is there any way I could get the user ID at this point? I would like to then create a user document with that ID to store additional fields from my signup form.

Currently, I have to wait until the user logs in and then redirect them to a form to finish getting the rest of the info, which is not ideal.

Hi Matt –

This is because the user is not technically created until they are confirmed and log-in.
After the user is registered (and depending on what your confirmation process is) you could simply send the credentials to the login endpoint (i.e. taking the login action on the user’s behalf). For creating the user document, a confirmation function (which will have the user ID) or a trigger on user creation are both options.

Hope that helps!

Ahh, I see. So that would require disabling the built-in email confirmations in order to log-in on their behalf right away. I was hoping I could keep Mongo’s email confirmation process, but it’s not the end of the world to make my own.