InertiaJS Route Guard Unauthenticated Response Customization
0 reputation · 19 Nov 2023, 22:43 UTC
InertiaJS's route protection middleware centrally handles unauthenticated access by redirecting to a login route. This behavior optimizes traditional server-rendered flows but does not provide a configuration option or hook to customize the response for client-side navigation scenarios, such as displaying a modal prompt or preserving the current page state.
Developers seeking a non-blocking unauthenticated experience must resort to overriding middleware logic or implementing workarounds that may not align with InertiaJS's core design principles. The middleware's default redirect assumes a full page transition, which conflicts with SPA-like interactions where inline feedback is preferred.
InertiaJS 2.x maintains this design choice without exposing a public configuration boundary for the unauthenticated response mode. What mechanisms could InertiaJS expose to allow developers to intercept or replace the default redirect with a custom unauthenticated handler? How should the framework balance default redirect behavior with flexible unauthenticated response options? Is there a recommended pattern for conditional unauthenticated handling based on route context or client type?