@kimmer in the controller that renders the page/view, are you passing through a "user" property at all? This could be overriding the $page.props.user data.
Inertia Jetstream question about $page.props.user
Here's something I don't really understand and I'm wondering if I'm doing the right thing.
I'm using Laravel with Jetstream/Inertia.
By default Jetsream (or Inertia) returns a user object in the $page.props.
I am building a backend where user account details can be updated.
Mostly the $page.props.user object contains the data fro the logged in user. However when I'm on an account update page the $page.props.user object contains the data of the user to be updated and no longer the logged in user.
The Applayout.vue component renders the users profile photo (in the header). this should, obviously, always be the profile photo of te logged in user. But since this profile image is gathered by taking the $page.props.user.profile_photo_url value the image in the header changes whenever an account/update page is showing.
To solve this I updated the share function app\Http\Middleware\HandleInertiaRequests.php to also share the Auth::user() object. Like this...
public function share(Request $request)
{
return array_merge(parent::share($request), [
'flash' => function () use ($request) {
return [
'success' => $request->session()->get('success'),
'error' => $request->session()->get('error'),
];
},
'auth' => Auth::user(),
]);
}
This gives me access to the Auth object to solve this image issue described above.
However, I am wondering if I'm doing the right thing. Shouldn't the $page.props.user object always contain the data for the logged in user? Or is it normal this data changes when a detailed page of any user is called?
Thanks!
Ah. Just noticed that it is indeed in the jetstream version :/ So either dont use that one, or live with having to use user as auth user
https://github.com/laravel/jetstream/blob/2.x/src/Http/Middleware/ShareInertiaData.php
Please or to participate in this conversation.