Authentication Overview
User sessions, Better Auth configuration, and security handling.
VibeKit uses Better Auth in packages/auth for all authentication and session handling.
How it works
- Client requests: Forms in
apps/web/modules/saas/authcall Better Auth client methods or tRPC endpoints. - Session storage: Sessions are persisted in the PostgreSQL
UserSessiontable using the Prisma adapter. - Session cookies: Better Auth issues an HTTP-only, secure
auth_sessioncookie to the browser. - Server validation: Server components and tRPC context read and validate the session cookie on each request.
// packages/auth/lib/auth.ts
export const auth = betterAuth({
baseURL: getBaseUrl(),
secret: process.env.BETTER_AUTH_SECRET,
database: prismaAdapter(db, { provider: "postgresql" }),
emailAndPassword: {
enabled: true,
autoSignIn: false,
requireEmailVerification: true,
password: {
hash: hashPassword,
verify: ({ hash, password }) => verifyPassword(hash, password),
},
},
// ... plugins and options
});Session types
packages/auth exports inferred TypeScript session types:
Session: The raw session object containing expiration, IP address, and token.SessionUser: The active user record containingid,email,name,role,avatarUrl, andonboardingComplete.
Explore available sign-in options in Authentication Methods.
Connect external AI clients through scoped, read-only MCP access. Apply the OAuth migration before starting the updated app.