Hi! This is Yasin.
I have a question. Currently, I am using Auth0’s superior Actions feature to sync my user registration and login flows with my Hasura backend that I use for my Flutter mobile and desktop apps. I am not going to blast here with bunch of code but only the required ones.
The above is valid for flows with user credentials (email, username, password) and works as intended. For a second method of sign in, I wanted to use social sign in methods (mainly google-oauth2
but others would be good to have).
I have managed to setup Auth0 and my Google Dev account to work together. I have managed to redirect from my Flutter desktop (MacOS) app to Safari browser page and sign in with an existing Google account of mine.
The Google sign in is accepted by Auth0 as intended. However, my Post Login Action doesn’t work. I am asking for what changes I can make it work with social logins too.
Pre Registration Action
- When registering a new user with
email, username, password
, check if there is already a user with theseemail OR username
on Hasura. - If not, it is okay to create a user on Hasura first. Then get the
Hasura.user.id
andapi.user.setUserMetadata("hasuraUser", hasuraUser)
on Auth0. - If there is already a user with these credentials on Hasura, registration must be denied. →
api.access.deny("NOT_UNIQUE_CREDENTIALS", errorMessage);
Post Login Action:
- Checks if my Hasura DB also has a user with credentials
event.user.email
ORevent.user.username
. - If a user found in Hasura, everything is okay. Get the
Hasura.user.id
and set custom claims accordingly. Allow login. - If no user found, this means even though Auth0 already accepted the login, I still can not accept it because there is a sync issue between Auth0 users and Hasura users. So the code simply does this →
api.access.deny("NO_USER_FOUND_ON_HASURA")
.
What I Think the Problem Is
I think a social login flow happens like that.
→ “Hey, this is a valid social login with this email. Since it is a valid social login, I firstly created the user on Auth0 while login the user in but I didn’t trigger Pre Registration Action. So I know that you couldn’t create/sync that user on Hasura.”
Possible solution:
→ Option 1: Social login methods of Auth0 should trigger PreRegistration before login.
→ Option 2: After a social login, PostLogin action is triggered. I need to modify the action so that instead of denying the login, if it is a valid social login, I should accept it but at the same time,
-
create the user on Hasura
, - Get the
Hasura.user.id
- Set
user_metadata
on Auth0, - Set
custom claims
withHasura.user.id
.
So what should I do?
Thanks a lot!