Skip to content

Commit 211ca6e

Browse files
authored
docs: improve set active organization guide (better-auth#7010)
1 parent d45198d commit 211ca6e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docs/content/docs/plugins/organization.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,19 +637,20 @@ type setActiveOrganization = {
637637
```
638638
</APIMethod>
639639
640-
To set active organization when a session is created you can use [database hooks](/docs/concepts/database#database-hooks).
640+
To automatically set an active organization when a session is created, you can use [database hooks](/docs/concepts/database#database-hooks). You'll need to implement logic to determine which organization to set as the initial active organization.
641641
642642
```ts title="auth.ts"
643643
export const auth = betterAuth({
644644
databaseHooks: {
645645
session: {
646646
create: {
647647
before: async (session) => {
648-
const organization = await getActiveOrganization(session.userId);
648+
// Implement your custom logic to set initial active organization
649+
const organization = await getInitialOrganization(session.userId);
649650
return {
650651
data: {
651652
...session,
652-
activeOrganizationId: organization.id,
653+
activeOrganizationId: organization?.id,
653654
},
654655
};
655656
},

0 commit comments

Comments
 (0)