Migrating an existing BFF guard

Move from a global middleware or an older version to defineBffHandler.
  1. Move the identity check into verifyUser. Bring the Cookie name, the token checks and the app-wide 403 rule with it.
  2. Wrap each protected route. Replace defineEventHandler with defineBffHandler. If a middleware attached credentials or forwarded requests upstream, move that into a function the handler calls after the guard.
  3. Find the public routes. Walk through sign-in, sign-out and token refresh with no Cookie, a deleted Cookie and an expired one. Mark the routes those states need with { access: 'public' }.
  4. Replace internal HTTP calls. Routes that only your server called become server functions in server/utils/, called directly.
  5. Remove old options. apiPrefix, publicPaths and internalRequests from older versions stop the startup with an error, so nothing is dropped silently. Remove any internal request marker and any replaced global $fetch as well.
  6. Verify. Call the BFF without credentials and expect 401 from every protected route. Then check the public routes, sign-in from a fresh browser profile, sign-out, and token refresh.