Only sign up user if own backend allows it and send (sub, email, username)

Hey I got some questions regarding my usecase:
I want to gather data (auth0_sub, email, username) and send it to my backend to create a user with said fields. I then send back the associated internalId from my backend as a response and put it into app_metadata. If theres no correct response the user should not get signed up.

Two problems:

  • With the pre user registration hook I only get the email send to my backend, no auth0 sub? When I was using rules that worked though. Is it because rules run after registration when theres a auth0 sub created? Are you all querying data for your users based on their email?
  • Do pre user registration actions only run for Auth0 registrations? The calls made from the action are not being made for Spotify registrations. That way I literallly can’t track if a user signed up using Spotify for example…

I am stuck in a loop. I can use pre user registration actions for getting an internalId into the app_metadata of the user and use that to fetch data. But then Spotify users aren’t registered at my backend. For that I would need post user registrations I assume, but in that case, I can’t deny registration if something fails on my backend. Plus the @nextjs-auth0 useUser() hook doesn’t provide the app_metadata. Heavily disappointed by how all this is documented somehow… Googling and writing for days now. A seperated frontend/backend is industry standard though, how do these need custom actions and what not?

This is my current action:

Hello @amg1!

A few things to clarify, pre-user registration only triggers with Database and Passwordless users, not social logins. When using api.access.deny(), the user will still be created, even if they have no access.

You can use the Post-Login trigger to get the user_id and get the sub claim to send to your backend and deny access.

The action itself looks good, just make sure you are using the sub claim in the post-login and assume that the pre-user registration aspects are assuming a database or passwordless connection, not a social.

I hope this helps!

Best,
Alex

1 Like

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