1
votes

I am in a bit of pickle. I am using Auth::login() to login the administrator. But after I login him (the login passed and at the moment the Auth::check returns true) and use redirect::route() to the admin panel , the Auth::check returns false. I check the other solutions, but my routes are placed in the web middleware group, so the session should be working. Any Ideas?

The last part of authentication

$admin = $this->setAdmin($user); 
Auth::login($admin); 
return Redirect::route('admin.panel');

Routes (they are also enclosed in ['middleware' => ['web']])

Route::group(['middleware' => 'auth', 'namespace' => 'Admin'], function(){ 
        Route::get('/', [ 'as' => 'admin.panel', 'uses' => 'AdminController@index' ]); 
    })

Basic middleware

if (Auth::check()) {
  return $next($request); 
} 
return redirect('/');
1
Post some code please. - Jilson Thomas
Well there is not much to it ` $admin = $this->setAdmin($user); Auth::login($admin); return Redirect::route('admin.panel');` and then the admin panel is inside the auth middleware group ` Route::group(['middleware' => 'auth', 'namespace' => 'Admin'], function(){ Route::get('/', [ 'as' => 'admin.panel', 'uses' => 'AdminController@index' ]); });` and the middleware is also very basic ` if (Auth::check()) { return $next($request); } return redirect('/');` - MattJ
And by the way I just quick checked the session with session(['key' => 'tatat']); and I get the same value after redirect, so the session is fine. I did not mention, but I deleted all the laravel default authentication controllers, could that cause this? - MattJ
post that in the question section - Jilson Thomas

1 Answers

0
votes

I didn't read up properly, on how Auth::login works, apparently, there has to be an entry in the database (users table), even if you want to login the user manually.