Migrating an existing BFF guard
Move from a global middleware or an older version to defineBffHandler.
- Move the identity check into
verifyUser. Bring the Cookie name, the token checks and the app-wide 403 rule with it. - Wrap each protected route. Replace
defineEventHandlerwithdefineBffHandler. If a middleware attached credentials or forwarded requests upstream, move that into a function the handler calls after the guard. - 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' }. - Replace internal HTTP calls. Routes that only your server called become server functions in
server/utils/, called directly. - Remove old options.
apiPrefix,publicPathsandinternalRequestsfrom older versions stop the startup with an error, so nothing is dropped silently. Remove any internal request marker and any replaced global$fetchas well. - 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.