mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 16:36:34 -05:00
64 lines
1.7 KiB
Plaintext
64 lines
1.7 KiB
Plaintext
---
|
|
title: Solid Start
|
|
description: Solid Start integratons guide
|
|
---
|
|
|
|
|
|
## Installation
|
|
|
|
First, install Better Auth
|
|
|
|
```package-install
|
|
npm install better-auth
|
|
```
|
|
|
|
## Set Environment Variables
|
|
|
|
Create a `.env` file in the root of your project and add the following environment variables:
|
|
|
|
**Set Base URL**
|
|
```txt title=".env"
|
|
BETTER_AUTH_URL=http://localhost:3000 # Base URL of your Next.js app
|
|
```
|
|
|
|
**Set Secret**
|
|
|
|
Random value used by the library for encryption and generating hashes. You can generate one using the button below or you can use something like openssl.
|
|
```txt title=".env"
|
|
BETTER_AUTH_SECRET=
|
|
```
|
|
|
|
<GenerateSecret/>
|
|
|
|
## Configure Server
|
|
|
|
### Create Better Auth instance
|
|
|
|
We recommend to create `auth.ts` file inside your `lib/` directory. This file will contain your Better Auth instance.
|
|
|
|
```ts twoslash title="auth.ts"
|
|
import { betterAuth } from "better-auth"
|
|
|
|
export const auth = betterAuth({
|
|
database: {
|
|
provider: "sqlite", //change this to your database provider
|
|
url: "./db.sqlite", // path to your database or connection string
|
|
}
|
|
// Refer to the api documentation for more configuration options
|
|
})
|
|
```
|
|
|
|
<Callout type="warn">
|
|
Better Auth currently supports only SQLite, MySQL, and PostgreSQL. It uses Kysely under the hood, so you can also pass any Kysely dialect directly to the database object.
|
|
</Callout>
|
|
|
|
### Mount the handler
|
|
|
|
We need to mount the handler to Solid Start server. Put the following code in your `*auth.ts` file inside `/routes/api/auth` folder.
|
|
|
|
```ts title="*auth.ts"
|
|
import { auth } from "~/lib/auth";
|
|
import { toSolidStartHandler } from "better-auth/solid-start";
|
|
|
|
export const { GET, POST } = toSolidStartHandler(auth);
|
|
``` |