AuthenticateMiddleware ​
File: src/Http/Middleware/AuthenticateMiddleware.php
Alias: modularous.auth
Extends: Illuminate\Auth\Middleware\Authenticate
Extends Laravel's built-in Authenticate middleware with two Modularous-specific behaviours: intended-URL preservation before the redirect and JSON 401 handling for Inertia/AJAX requests.
Behaviour ​
Standard HTML requests ​
When an unauthenticated browser request hits a protected route:
- The current URL is saved to
session('url.intended')viasession()->put('url.intended', url()->previous()). - The user is redirected to the admin login route (
admin.login.form).
Excluded routes — the intended URL is NOT stored when the current route is any of:
| Route name (prefixed) |
|---|
login.form, login, logout |
register.form, register, register.success |
password.reset.* |
impersonate, impersonate.stop |
This prevents the login page itself (or other auth pages) from being set as the post-login destination.
JSON / Inertia requests ​
When the request expects JSON (Accept: application/json):
- The
Refererheader is stored insession('url.intended'). - Returns a
401 JSONresponse:json{ "message": "Unauthenticated.", "mode": "experimental" }
Usage ​
Applied via the web.auth and api.auth middleware groups:
Route::middlewareGroup('web.auth', [
'web',
'modularous.auth:modularous',
]);The guard name is injected from Modularous::getAuthGuardName() (default: 'modularous').
Notes ​
- After a successful login, the
RedirectServiceor Laravel'surl()->intended()uses the stored URL to redirect the user back. - The
mode: experimentalfield in the JSON 401 is a placeholder for future Inertia partial-reload handling.