Public routes
Health checks, sign-in entry points and other routes without a user.
Some routes must work before anyone is signed in. Mark them on the route itself:
server/api/health.get.ts
import { defineBffHandler } from '#bff-guard'
export default defineBffHandler(() => ({ ok: true }), { access: 'public' })
A public route does not call verifyUser. It still sets Cache-Control: private, no-store, and its writes still need the same-origin check.
Finding the routes that must be public
Walk through your sign-in flow with a fresh browser profile: no Cookie yet, a deleted Cookie, an expired Cookie. Every API the flow calls in those states must be public. Typical examples:
- a route that exchanges an ID token for a session Cookie
- sign-out, which must work with an expired session
- health and readiness checks
- data that pages load during server-side rendering, which anyone can read by opening the page
Webhooks from other servers are different: they send no Origin, so the same-origin check rejects their POSTs. Put them outside server/api; see Webhooks.
Rules for public routes
- Do the route's own verification: an ID token, a bot check.
- Return only data that may be public.
- Keep public routes small. Do not route from a public catch-all into protected logic; the public flag belongs to that one handler.
The setting is bound to the handler, not to a path. A change in path normalization cannot move it to another route.