Skip to main content

Imports

import {
  authenticateRequest,
  getAuth,
  requireAuth,
  wachtClient,
  createWachtServerClient,
} from '@wacht/tanstack-router/server'

authenticateRequest contract

const { auth, headers } = await authenticateRequest(request, options)
Always merge returned headers into your response to preserve cookie/session state.

Typical redirect flow

if (!auth.userId) {
  return new Response(null, {
    status: 302,
    headers: {
      ...Object.fromEntries(headers.entries()),
      Location: '/sign-in',
    },
  })
}

Backend client helpers

const client = await wachtClient()
or:
const client = createWachtServerClient({
  apiKey: process.env.WACHT_API_KEY,
  name: 'server-actions',
})