0
votes

I am having issues with authentication in laravel 5.3. I have protected routes that can only be accessed by the logged in users with the auth middleware. However the problem is that whenever a logged in users attempt to access auth protected routes instead of proceeding the access the page are being redirected back to home page

This my routes:

Route::group(['middleware'=>['web','auth']],
function()
{
Route::get('/members/index',['as'=>'memberlist','uses'=>'MembersController@index');

});

Redirect users after login property in LoginController

 protected $redirectTo = '/home';
  public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }

RedirectifAuthenticated.php middleware class -handle method

public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
             return redirect()->intended('/');
        }

        return $next($request);

        }

The question is, what Am I supposed to do so as authenticated users can access the routes protected with auth middleware instead of being redirected to home page whenever they attempt to access these routes. They are logged in but being auto-redirected to homepage! Please help.

1

1 Answers

0
votes

you can use

public function __construct(){
$this->middlleware('auth:admin');
}

for pages where you want to protect from unauthenticated users