Auth::user() returns null in Livewire components using the web guard
Livewire version v3.5.9
Laravel version v11.26.0
Which PHP version are you using? PHP 8.2
Steps To Reproduce Install a fresh Laravel 11.x application. Install Livewire v3.x. Set up basic authentication in Laravel using the web guard. I'm using the file session driver. I've verified that the auth:web middleware is applied correctly to my web routes. I can successfully log in and obtain an access token using Passport in my API. I'm able to retrieve user information in my API routes using Auth::user(). Create a Livewire component and attempt to retrieve the authenticated user in the mount() method using Auth::guard('web')->user(): public function mount() { $this->user = Auth::guard('web')->user(); }
Protect routes with the auth middleware to ensure the session is authenticated: Route::middleware('auth')->get('/dashboard', \App\Http\Livewire\Dashboard::class);
Attempt to retrieve Auth::user() within the Livewire component, but it consistently returns null.
Expected Behavior: I expect to be able to retrieve the authenticated user information using Auth::user() in both my API and web routes.
Actual Behavior: Auth::user() is returning null in my web routes.
Additional information SessionGuard is correctly initialized, but Auth::user() is returning null in Livewire components, even though the session-based authentication works perfectly in regular web routes. Middleware such as Authenticate is correctly set up in the web middleware group. I have verified that sessions are being managed correctly, and there is no issue with session persistence in regular web routes. Tried clearing cache (php artisan config:clear, cache:clear, etc.), adjusting session configuration (session.php), and testing on different browsers, but the issue persists. Session Driver is set to file in config/session.php, and cookies are correctly configured. Routes protected by the auth middleware work fine, but Livewire components do not have access to the authenticated user.
Please or to participate in this conversation.