How can I do multiple Database calls 'during' user creation transaction in google OAuth?
Is there a way to write/hook into the User creation code when signing up with google ?
I know that I can use the databaseHooks 'before' and 'after', but I want to do something 'during' the User DB creation that does multiple database inserts on signUp, because I want to use transactions to make sure they either all succeed or all fail, like this:
'before' and 'after' database hooks dont give me access to the user creation step, so how can I do this in betterAuth?
If I put the Lists code in the after hook, and the after hook errors, it still keeps the user created, so I can end up with a user that doesnt have the documents they are supposed to have when they sign up
6 Replies
there is no such thing with BA but if the oauth succeed , you can batch your external transaction and execute them. if not you can delete from your db right away when the transactions fails.
I mean you can try to hook up into OAuth flow of better auth by specifying the custom redirectURI for provider in auth config an doing your transaction there . link to docs: https://www.better-auth.com/docs/concepts/oauth
You will need to handle this part by yourself then I guess: https://www.better-auth.com/docs/concepts/oauth#post-login-flow
OAuth | Better Auth
How Better Auth handles OAuth
I can give and example of how I handled google OAuth flow when used the Lucia if you want
yeah that is another way of hooking in to flow.
send it over
Thank u very much guys, I'll look into the redirectURI route approach, or if not I'll do the rest of the transaction in the after hook and if the transaction fails then delete user (although user deletion can fail too I imagine ðŸ˜)
Would be awesome if BetterAuth added some way to simplify this, so we could just write the code that goes in the user creation step 🙂