create organization in databaseHooks.user.create.after

I want to ensure that for all created users without an invite link, an organization (using the organization plugin) is created for them automatically on sign up.
Ideally also set this freshly created organization as their active organization on the client.

Is there a way to create an organization for a user that has just been created? I was thinking of using this database hook:

const auth = betterAuth({
  database: mongodbAdapter(client.db()),
  plugins: [
    organization({ allowUserToCreateOrganization: false })
  ],
  databaseHooks: {
    user: {
      create: {
        after: async (user) => {
          // create organization for user - can't access the server auth api, can I?
        }
      }
    }
  },
  // ...
})

Any workarounds or solutions for this? Thank you!
Solution
To follow up ^^, here is how you can create org from server auth api:
image.png
Was this page helpful?