here is my inertia.ts
sharedData: { greetings: 'bonjour', user: (ctx) => ctx.auth.user, errors: (ctx) => ctx.session?.flashMessages.get('errors'), },
Copied!
Here is a page:
interface Props extends PageProps {} const SigninPage = () => { const { errors, greetings, user } = usePage<Props>().props console.log({ user, errors, greetings }) }
Copied!
I get the greetings
but not errors
or user
Join The Discussion! (6 Replies)
Please sign in or sign up for free to join in on the dicussion.
tomgobich
Hi Michel,
Are you sure you have an authenticated user and/or errors? Try giving them a console log inside the
sharedData
just to make sure you actually have a value there. This has been the reason for a few others in the past.Also, if you're using v3 of the AdonisJS Inertia adapter or later, you don't need to manually pass the errors via
sharedData
, the package will now do that automatically.Please sign in or sign up for free to reply
michel-mbili
I've
undefined
foruser
anderrors
.here is what I've done in my signin_controller
Maybe it can help understand what's going on
Please sign in or sign up for free to reply
michel-mbili
Please sign in or sign up for free to reply
tomgobich
I'm guessing you're probably using v3 or later of the AdonisJS Inertia adapter and
errors
is already being shared automatically for you.Since you're sharing to a custom
errors
key in your flash messages, that won't be included within those.Try writing to the
errorsBag
instead. This is how the invalid credentials exception does it itself, and this is automatically checked and populated by the AdonisJS Inertia adapter (v3+).Then, so long as my assumption is correct and you're using v3 or later of the adapter package, you can remove
errors
from yoursharedData
Please sign in or sign up for free to reply
michel-mbili
Thank you so much!
Yeah I'm using
"@adonisjs/inertia": "^3.1.0"
It all works now. For the user I didn't useauth middleware
on my route that's why I was not getting theuser
Please sign in or sign up for free to reply
tomgobich
Awesome, glad to hear all is working now!
Yep, that'll do it! You'll want to either use:
The auth middleware (requires an authenticated user)
The silent auth middleware (checks for user, but does not require auth)
Or, call
await auth.check()
to check for an authenticated user without one of the two middleware.Please sign in or sign up for free to reply