Sean Drumm
Sean Drumm
BABetter Auth
Created by Sean Drumm on 4/13/2025 in #help
auto-creating organization on user signup?
Has anyone managed to do this? Want to ensure users always have an org, i.e. a personal tenant even on signup. I did this through the UI but its pretty clunky. I tried this already:
databaseHooks: {
user: {
create: {
after: async (user) => {
const org = await auth.api.createOrganization({
body: {
name: `${user.name}'s Organization`,
slug: `${Math.random().toString(36).substring(2, 15)}-${user.name}s-organization`,
userId: user.id,
},
})

await auth.api.setActiveOrganization({ body: { organizationId: org?.id } })
},
},
},
databaseHooks: {
user: {
create: {
after: async (user) => {
const org = await auth.api.createOrganization({
body: {
name: `${user.name}'s Organization`,
slug: `${Math.random().toString(36).substring(2, 15)}-${user.name}s-organization`,
userId: user.id,
},
})

await auth.api.setActiveOrganization({ body: { organizationId: org?.id } })
},
},
},
6 replies