mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-04 05:16:36 -05:00
* fix(docs): use `APIRoute` instead of `Route` for tanstack start api routes * fix(cli): remove unused import in drizzle schema
30 lines
822 B
Plaintext
30 lines
822 B
Plaintext
---
|
|
title: TanStack Start Integration
|
|
description: Integrate Better Auth with TanStack Start.
|
|
---
|
|
|
|
This integration guide is assuming you are using TanStack Start.
|
|
|
|
Before you start, make sure you have a Better Auth instance configured. If you haven't done that yet, check out the [installation](/docs/installation).
|
|
|
|
### Mount the handler
|
|
|
|
We need to mount the handler to a TanStack API endpoint.
|
|
Create a new file: `/app/routes/api/auth/$.ts`
|
|
|
|
```ts
|
|
import { auth } from '@/lib/auth'
|
|
import { createAPIFileRoute } from '@tanstack/start/api'
|
|
|
|
export const APIRoute = createAPIFileRoute('/api/auth/$')({
|
|
GET: ({ request }) => {
|
|
return auth.handler(request)
|
|
},
|
|
POST: ({ request }) => {
|
|
return auth.handler(request)
|
|
},
|
|
})
|
|
```
|
|
|
|
This will allow you to access use the `getSession` method in all of your routes.
|