Oauth new user
Hi, having a lot of success so far with better-auth, it has been a joy to use.
My issue at the moment is that I want to have social login and signup, but need them to be on separate paths. At the moment, if I don’t have an account and login, it automatically creates a new account and logs me in - I would like to catch that early and not create the account until the new user has gone through the sign up process.
I know I can manage it with a flag for a new user which the app will check against each time, then delete the user if they don’t finish signing up, but that feels a little clunky.
Does anyone have a good process for dealing with this situation, or is the new user flag the best solution?
Thanks
7 Replies
Hooks
Hooks | Better Auth
Better Auth Hooks let you customize BetterAuth's behavior
Thanks, I’ll have a look into that. Not sure if I am misunderstanding, but it looks like the hook will either run before login (in which case I don’t know if the user existed) or after login (in which case the new user has been created).
What I need to do is hook between the login attempt and the new user creation. Or alternatively, disable new user creation, just reject the login if the user doesn’t exist. I’ve looked into the source code, and the current system doesn’t seem to give me many options.
From the requirements your telling me you need, You should use hooks
You want to catch early and not create an account right? use a before hook to catch early (aka before).
Now if you don't want the user to access the app before completing a form add a db field like hasCompletedSignup then use a before hook to check for the field and if the user has completed signup if not then block the request (email verification does a similar thing with a emailVerified field)
Here are docs for both database hooks and extending user schema
https://www.better-auth.com/docs/concepts/database#database-hooks
https://www.better-auth.com/docs/concepts/database#extending-core-schema
Database | Better Auth
Learn how to use a database with Better Auth.
Thanks for your help. Looks like v1.2 has addressed this issue as well (disableImplicitSignup). Which means I should be able to have a separate ‘sign up with Google’ path I think.
I didn't realise glad its fixed for you!