Set active org on login

I want each user to always have one active org set when they log inn, no user should ever find themselves without an active org.

Docs at https://www.better-auth.com/docs/plugins/organization indicate that I can use a database hook to achive this
export const auth = betterAuth({
  databaseHooks: {
      session: {
          create: {
              before: async(session)=>{
                  const organization = await getActiveOrganization(session.userId)
                  return {
                    data: {
                      ...session,
                      activeOrganizationId: organization.id
                    }
                  }
              }
          }
      }
  }
})

My question is, is getActiveOrganization somehow an already made function? It seems to not exist and not work, so would I have to to create this function myself?

And what benefits would I get from doing it as DB hooks instead of adding it to my login flow code? Thi seems to take in session.userId so presumably I'd have to write all the code I'd need to write anywhere else to set an active org.
The organization plugin allows you to manage your organization's members and teams.
Was this page helpful?