Open History to see the last commit
1## Setting up Better Auth
2
31. Generate and set the `BETTER_AUTH_SECRET` environment variable in your `.env.local`:
4
5 ```bash
6 <%- getPackageManagerExecuteScript('@better-auth/cli', ['secret']) %>
7 ```
8
92. Visit the [Better Auth documentation](https://www.better-auth.com) to unlock the full potential of authentication in your app.
10
11<% if (addOnEnabled.drizzle || addOnEnabled.prisma) { %>
12### Create the auth tables
13
14Better Auth uses your <%= addOnEnabled.drizzle ? 'Drizzle' : 'Prisma' %> database. Its user, session, account, and verification tables are included in <%= addOnEnabled.drizzle ? '`src/db/schema.ts`' : '`prisma/schema.prisma`' %>.
15
16Set `DATABASE_URL` in `.env.local`, then <% if (addOnEnabled.prisma) { %>run the `db:generate` package script to update the Prisma client and <% } %>run the `db:push` package script to create the tables. Use the ORM's migration workflow when deploying schema changes to an existing database.
17<% } else { %>
18### Adding a Database (Optional)
19
20Better Auth can work in stateless mode, but to persist user data, add a database:
21
22```typescript
23// src/lib/auth.ts
24import { betterAuth } from "better-auth";
25import { Pool } from "pg";
26
27export const auth = betterAuth({
28 database: new Pool({
29 connectionString: process.env.DATABASE_URL,
30 }),
31 // ... rest of config
32});
33```
34
35Then run migrations:
36
37```bash
38<%- getPackageManagerExecuteScript('@better-auth/cli', ['migrate']) %>
39```
40
41<% } %>