Security
Authentication & Teams
Complete guide to session management, Better-Auth configuration, and multi-tenant teams.
Authentication is powered by Better-Auth with the Drizzle adapter, supporting email/password authentication, GitHub OAuth, and role-based permissions (admin vs user).
src/lib/server/auth/index.ts
export const auth = betterAuth({
baseURL: dev ? 'http://localhost:5173' : env.ORIGIN,
secret: env.BETTER_AUTH_SECRET,
database: drizzleAdapter(db, { provider: 'pg', schema }),
plugins: [
admin({ defaultRole: 'user', adminRole: 'admin' }),
organization({ allowUserToCreateOrganization: true }),
sveltekitCookies(getRequestEvent)
]
});Users can create workspaces, invite team members with specific roles (owner, admin, member), and switch active organizations seamlessly with instant session state synchronization.