omero
omero
BABetter Auth
Created by omero on 4/23/2025 in #help
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:
const onSignUp = async() => {
const session = await mongoose.startSession();

await session.withTransaction( async () => {
// create user
const newUser = await User.create({}, {session});

// create bookmarks list for user
const newList = await List.create({user: newUser.id}, {session});
newUser.defaultLists.bookmarks = newList;
await newUser.save().session(session);
})
}
const onSignUp = async() => {
const session = await mongoose.startSession();

await session.withTransaction( async () => {
// create user
const newUser = await User.create({}, {session});

// create bookmarks list for user
const newList = await List.create({user: newUser.id}, {session});
newUser.defaultLists.bookmarks = newList;
await newUser.save().session(session);
})
}
'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
9 replies