Skip to content

Document middleware on native routes - #474

Open
shanerbaner82 wants to merge 2 commits into
mainfrom
docs/native-route-middleware
Open

Document middleware on native routes#474
shanerbaner82 wants to merge 2 commits into
mainfrom
docs/native-route-middleware

Conversation

@shanerbaner82

Copy link
Copy Markdown
Contributor

Pairs with NativePHP/mobile-air#252 / NativePHP/mobile-air#348, which makes Route::native()->middleware() run on every navigation rather than only on cold start.

New page at the-basics/middleware (order 153, right after Routing), plus a pointer to it from the Routing page's "Registering routes" section.

Covers:

  • ->middleware() and route groups, both of which now work unchanged
  • why native middleware is different — the app enters its runloop once, so only the launch screen arrives as an HTTP request
  • what the synthesized request does and does not carry. It has the live session, user resolver, cookies and server bag; it has no body, query string, files, real headers or client IP, and the method is always GET. This is the deliberate trade-off in the implementation and the main thing users need to know before relying on it
  • which request-lifecycle middleware is skipped, and ScreenGuard::skip() for opting your own out
  • how a refusal maps onto native navigation, plus the two guarantees (a refused screen never mounts; guards fail closed)
  • why Native::visit() exercises a guard and Native::test() deliberately doesn't — the distinction that let this bug hide from an otherwise thorough suite

Should land with (or just after) the mobile-air PR, since it documents behavior that doesn't exist yet.

Covers how `Route::native()->middleware()` and route groups apply on every
navigation, what the synthesized request does and does not carry, which
request-lifecycle middleware is skipped and how to opt your own out, how a
refusal maps onto native navigation, and why `Native::visit()` rather than
`Native::test()` is what exercises a guard.

Pairs with NativePHP/mobile-air#252.
The route is bound to the synthesized request, not merely resolvable, so
route parameters and route-model binding work — worth stating, since
SubstituteBindings runs on every navigation.

That happens more often than the previous wording implied: registering
native routes through `withRouting(web: routes/mobile.php)` puts every one
of them in the `web` group, so anything an app has added to that group runs
per navigation too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant