Hi! We have the following scenario and want our uses to be logged in automatically after registration:
- nextjs application using nextjs-auth0 sdk
- custom html form for registration
- user clicks submit on registration form, request is made to our external api
- external api creates a user in our local db and an auth0 user
- response comes back successfully
At this point, we want to have our users logged in automatically so they don’t have to take an extra step after registration. How would we go about doing this?
The nextjs-auth0 sdk doesn’t appear to have any
login method on it. Would we use something like this or a POST request to the auth0 api to use the form’s username/password to authenticate?
Welcome to the Auth0 Community!
I understand you would like to set up automatic login after user registration.
Unfortunately, it is not possible to automatically log in after the user is created in your current approach. This is because the user is being created by making an API call such as the Management API’s Create a User endpoint or the Authentication API’s Signup endpoint.
When doing so, the user is only created but never inputs their credentials to login. Moreover, there isn’t any way to log the user in without prompting for credentials.
With that, allow me to offer an alternative solution that may work for you.
First, I recommend using the Universal Login experience, so that your users have a centralized login experience. Let me emphasize that users are automatically logged in after signing up when using the Universal Login experience.
Then, to collect additional information from your users, there are two ways to accomplish this, namely:
Configuring addtionalSignupFields on the Universal Login, or,
Redirecting your users Post-Login to a separate page to fill in more information on their first-time login before resuming authentication.
After this is complete, you can use another Post-Login Action to create the user in your local Database. See this FAQ for more information.
I hope this helps!
Please let me know if you need help with implementation or further clarification.