DatabaseHooks Session Create Before
Why won't
authClient.getSession()
show my new activeOrganization
property with id
an slug
? I only see activeOrganizationId
which I want to get rid of now that I am adding slug
. I am pretty sure activeOrganizationId
is added automatically by the organization
plugin2 Replies
We don't support just passing an object in the
data
as it means you're inserting an object into your DB - which we don't support.
You'll need to change that to be something like activeOrganizationId
and activeOrganizationSlug
.
Also make sure to add these as additional fields part of the session: https://www.better-auth.com/docs/concepts/typescript#additional-fieldsTypeScript | Better Auth
Better Auth TypeScript integration.
What I did,
1. Update database hook as you see
2. Update betterAuth server instance session data
3. Add column in session table with drizzle
4. Update authClient with new attribute (separate setup)
weird activeOrganizationSlug is null.
But now that I think about it, I shouldn’t be adding properties of another entity in sessions like this…
I think the better way is authClient maybe supported getting relationships if id is present. If not, need to make two network calls.
1. Getting session.
2. Get active organization id from session and use that to make a network call to getFullOrganization.