Auth.js integration for TanStack Start
npm install start-authjsAuth.js integration for TanStack Start and SolidStart applications.
``bash`
npm install start-authjs @auth/core
`bash
AUTH_SECRET=your-secret-key # openssl rand -base64 32
AUTH_URL=http://localhost:3000/api/auth
$3
`ts
// src/utils/auth.ts
import Auth0 from '@auth/core/providers/auth0'
import type { StartAuthJSConfig } from 'start-authjs'export const authConfig: StartAuthJSConfig = {
secret: process.env.AUTH_SECRET,
providers: [Auth0()],
}
`$3
TanStack Start:
`ts
// src/routes/api/auth/$.ts
import { createFileRoute } from '@tanstack/react-router'
import { StartAuthJS } from 'start-authjs'
import { authConfig } from '~/utils/auth'const { GET, POST } = StartAuthJS(authConfig)
export const Route = createFileRoute('/api/auth/$')({
server: {
handlers: {
GET: ({ request }) => GET({ request, response: new Response() }),
POST: ({ request }) => POST({ request, response: new Response() }),
},
},
})
`SolidStart:
`ts
// src/routes/api/auth/[...solidauth].ts
import type { AuthRequestContext } from "start-authjs";
import { StartAuthJS } from 'start-authjs'
import { authConfig } from '~/utils/auth'const { GET: AuthGET, POST: AuthPOST } = StartAuthJS(authConfig)
export const GET = (event: AuthRequestContext) => {
return AuthGET({ request: event.request, response: new Response() })
}
export const POST = (event: AuthRequestContext) => {
return AuthPOST({ request: event.request, response: new Response() })
}
`$3
`ts
import { getSession } from 'start-authjs'
import { authConfig } from '~/utils/auth'const session = await getSession(request, authConfig)
`API
| Export | Description |
|--------|-------------|
|
StartAuthJS | Creates GET/POST handlers for auth routes |
| getSession | Get current session from request |
| auth | Get session with cookie forwarding |
| authMiddleware | Middleware for protected routes |
| serverSignIn | Programmatic sign in |
| serverSignOut` | Programmatic sign out |- TanStack Start + React + Auth0
- TanStack Start + Solid + Auth0
- SolidStart v1
- SolidStart v2 Alpha
All Auth.js providers are supported: GitHub, Google, Auth0, Discord, Credentials, and 80+ more.
MIT