| 1 | --- |
| 2 | title: Better Auth |
| 3 | description: Build authentication with an Effect service, automatic database bindings, and deploy-time migrations. |
| 4 | --- |
| 5 | |
| 6 | Build sign-in and protected APIs with [Better Auth](https://better-auth.com), using ordinary Effect services and layers. Alchemy supplies database bindings, a stable signing secret, and supported schema migrations. |
| 7 | |
| 8 | ## Start the tutorial |
| 9 | |
| 10 | ```typescript |
| 11 | import { BetterAuth } from "@alchemy.run/better-auth"; |
| 12 | |
| 13 | const makeAuth = BetterAuth({ |
| 14 | basePath: "/api/auth", |
| 15 | emailAndPassword: { enabled: true }, |
| 16 | }); |
| 17 | ``` |
| 18 | |
| 19 | The [six-part tutorial](/better-auth/tutorial/part-1) turns this into a running application with browser sign-in, session middleware, and GitHub authentication. |
| 20 | |
| 21 | | Part | Build | |
| 22 | | --- | --- | |
| 23 | | [1. Create an Auth service](/better-auth/tutorial/part-1) | Install the module and provide a database layer | |
| 24 | | [2. Mount the HTTP API](/better-auth/tutorial/part-2) | Serve authentication and application routes | |
| 25 | | [3. Build sign-in](/better-auth/tutorial/part-3) | Sign up, sign in, read sessions, and sign out | |
| 26 | | [4. Protect API endpoints](/better-auth/tutorial/part-4) | Provide the current user through Effect middleware | |
| 27 | | [5. Add GitHub sign-in](/better-auth/tutorial/part-5) | Register an OAuth app and bind its credentials | |
| 28 | | [6. Deploy and verify](/better-auth/tutorial/part-6) | Configure production callbacks and check persistence | |
| 29 | |
| 30 | ## Choose a sign-in provider |
| 31 | |
| 32 | Use [email/password](/better-auth/sign-in-providers/email-password), [GitHub](/better-auth/sign-in-providers/github), [Google](/better-auth/sign-in-providers/google), [Microsoft](/better-auth/sign-in-providers/microsoft), or [custom OAuth](/better-auth/sign-in-providers/custom-oauth). Each guide covers registration, configuration, and browser sign-in. |
| 33 | |
| 34 | ## Choose a database |
| 35 | |
| 36 | Keep the Auth service and change the database layer. The [database guides](/better-auth/databases) cover D1, Hyperdrive, Neon, Aurora, Postgres, MySQL, Drizzle, SQLite, and memory. |
| 37 | |
| 38 | ## Extend the application |
| 39 | |
| 40 | Use [Config and secrets](/better-auth/guides/configuration) for deployment bindings, [HTTP API middleware](/better-auth/guides/http-api-middleware) for Effect handlers, and [secondary storage](/better-auth/guides/secondary-storage) for custom storage layers. |
| 41 | |
| 42 | For Better Auth's authentication features and options, see the [Better Auth documentation](https://better-auth.com/docs). |
| 43 | |
| 44 | ## Upgrade an existing installation |
| 45 | |
| 46 | The [1.6 → 1.7.5 upgrade guide](/better-auth/upgrades/from-1-6-to-1-7) separates package and API changes from manual data preparation. [Migrations](/better-auth/guides/migrations) explains what deployment applies automatically. |