How to access user/session data in 404 error handler when Session/Auth middleware are router-only? #5028
Unanswered
alberto-satsearch
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I’m using AdonisJS v6 with Inertia and have a question about middleware and 404 error handling.
According to the documentation and the default kernel.ts setup, session and auth middleware are registered as router middleware (i.e., router.use([...])), not as server middleware. This means they only run for requests that match a defined route.
The problem:
When a user visits a URL that does not match any route (404), the 404 error handler is triggered. However, since session and auth middleware are not run for these requests, the error handler (and any layout it renders) does not have access to user/session data (e.g., ctx.auth.user). This breaks layouts that expect user info (like name, avatar, etc.) to always be available.
What I’ve considered:
My questions:
Beta Was this translation helpful? Give feedback.
All reactions