Sites without users

Visitor routes inside a member app

access: 'visitor'verifyUser
Keep 'user' as the default and open a few routes to visitors without accounts.

A SaaS app protects its API with verifyUser, but its marketing pages have a demo request form and a pricing calculator for people who have not signed up yet.

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@kurashina-design/nuxt-bff-guard'],
  bffGuard: {
    // 'user' stays the default: every route needs a verified user unless it says otherwise.
    verifyUser: './server/auth/verify-user.ts',
  },
})
server/api/demo-request.post.ts
import { defineBffHandler } from '#bff-guard'

// No account yet, but only your own pages may send it.
export default defineBffHandler(async (event) => {
  await createLead(await readValidatedBody(event, leadSchema))
  return { ok: true }
}, { access: 'visitor' })
server/api/pricing.get.ts
import { defineBffHandler } from '#bff-guard'

// Rendered into the pricing page during SSR: public.
export default defineBffHandler(() => getPriceTable(), { access: 'public' })
server/api/invoices.get.ts
import { defineBffHandler } from '#bff-guard'

// The default: verifyUser must accept the request.
export default defineBffHandler(event => listInvoices(event.context.user!.id))

Reviewers see the exception on the route that makes it. A new route without an access option is protected by verifyUser, so forgetting the option fails closed.