Auth.js integration for TanStack Start and SolidStart applications.
npm install start-authjs @auth/coreAUTH_SECRET=your-secret-key # openssl rand -base64 32
AUTH_URL=http://localhost:3000/api/auth
# Provider-specific (e.g., Auth0)
AUTH_AUTH0_ID=your-client-id
AUTH_AUTH0_SECRET=your-client-secret
AUTH_AUTH0_ISSUER=https://your-tenant.auth0.com// 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()],
}TanStack Start:
// 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:
// 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() })
}import { getSession } from 'start-authjs'
import { authConfig } from '~/utils/auth'
const session = await getSession(request, authConfig)| 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 |
All Auth.js providers are supported: GitHub, Google, Auth0, Discord, Credentials, and 80+ more.
MIT