Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

⚡️ perf: optimize better-auth query speed with database joins (#10605)

17hz925d2fd04a07
diff --git a/src/auth.ts b/src/auth.ts
index 462aa7bd9e0..6323316ac42 100644
--- a/src/auth.ts
+++ b/src/auth.ts
@@ -122,6 +122,13 @@ export const auth = betterAuth({
database: drizzleAdapter(serverDB, {
provider: 'pg',
}),
+ /**
+ * Database joins is useful when Better-Auth needs to fetch related data from multiple tables in a single query.
+ * Endpoints like /get-session, /get-full-organization and many others benefit greatly from this feature,
+ * seeing upwards of 2x to 3x performance improvements depending on database latency.
+ * Ref: https://www.better-auth.com/docs/adapters/drizzle#joins-experimental
+ */
+ experimental: { joins: true },
/**
* Run user bootstrap for every newly created account (email, magic link, OAuth/social, etc.).
* Using Better Auth database hooks ensures we catch social flows that bypass /sign-up/* routes.