How to set username on OAuth signup?
I have
disableImplicitSignUp
enabled and want users to choose a username before signing up with OAuth.
Here’s the flow I’m aiming for:
1. User clicks "Sign in with Google"
2. A dialog appears before redirecting to Google, asking for:
A username
Agreement to Terms of Service, etc.
After submission:
- If the user already exists → proceed to sign in via Google
- If the user doesn't exist → store the username and proceed to Google
- After Google redirects back → create the account using the previously provided username
Note: I’m aware I can do this after with newUserCallbackUrl = "/complete-signup"
,but I want this step to happen before the Google sign-in redirect.
Is this possible?6 Replies
You may look into before and after hooks.
Hooks | Better Auth
Better Auth Hooks let you customize BetterAuth's behavior
Thanks Falcon, I actually played with it but here is the issue that I faced.
I could pass a
body:{username}
to the /sign-in
endpoint but how would I pass that to /callback/:id
?
I can change the response of /sign-in
but can I make /sign-in
pass more data to /callback/:id
?
Assuming i was able to pass it to /callback/:id
the user creation comes after this /cabllack/:id
, so how can I create a user with username?I see the issue u r facing. I don't have an answer for this right now until I try it myself.
However people were using some workarounds like setting a bool in user profile whether they have completed username choosing stage or not, if not force redirect them to username choosing page after sign in/sign up.
But that's a bit too much for this, you can look around the discord server for a solution which handles this within one flow. I remember people facing the same issue.
Great thanks. I took a look at GitHub, it looks like there is a pr and a feature request for signUp flows on OAuth.
Sadly not implemented yet. I'll see if there is no workaround I'm thinking of wrapping my head around the library and making a pr
Cool. Make sure to tag becka or ping