Auth::User() Returns Null

Auth::user() returns null

Any route that uses Auth() must be encapsulated in the web middleware. You're close, just move your Route::group(['prefix' => 'admin'], ...) into the group above.

Route::group(['middleware' => 'web'], function () {

Route::auth();

Route::get('/', 'HomeController@index');

// Moving here will ensure that sessions, csrf, etc. is included in all these routes
Route::group(['prefix'=>'admin', 'middleware' => 'admin'], function(){
Route::get('/', function(){
return view('admin.index');
});

Route::get('/user', function(){
return view('admin.user');
});
});
});

Auth::user() returns null in Laravel 6

So, I don't know why that happens, and after finally giving up, I came up with a (not so clean) solution.

Now, instead of using multiple guards, I'm creating a relationship from the users table to the guru/admin table.

This is how I access it now Auth::user()->guru or Auth::user()->admin

I know this is not a good solution, but it's the fastest workaround I can found

Auth::user() returns null in Laravel 5.2

Thank you guys.

The problem solved here:
https://laracasts.com/discuss/channels/laravel/authuser-returns-null-in-laravel-52

I had to add the stack into middleware directly (not in the group).

in /Http/kernel.php:

protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class
];

Laravel Auth::user() always null

I have fixed this error. I have created an authentication route in route/api.php. API route not supported to the session so it does not store user data in the session because that Auth::user() always returns null. please view this answer https://stackoverflow.com/a/44863089/13729121



Related Topics



Leave a reply



Submit