Can you show how you added HandleInteriaRequests to /app/Http/Kernel.php ? Maybe it comes before StartSession
Jun 29, 2022
8
Level 6
Inertia Auth()->User()->name is null
Feel Like I'm on this forum every day with Inertia haha.
If I dd() in my web route for dashboard after logging in:
Route::get('/', function() {
dd(auth()->user()->name);
return Inertia::render('Home');
});
This works and returns the logged-in user, However:
If I go to The Class HandleInteriaRequests to define my authenticated users name I get an error that its null there is no authenticated user any ideas 100% logged in
public function share(Request $request): array
{
return array_merge(parent::share($request), [
'auth' => [
'user'=> [
'username' => dd(auth()->user()->name)
]
]
]);
}
Level 102
@Elliot_putt Ok. Try lazy evaluation
return array_merge(parent::share($request), [
'auth' => [
'user'=> [
'username' => function() {
return dd(auth()->user()->name);
}
]
]
]);
2 likes
Please or to participate in this conversation.