Ad

Laravel Authentication Redirect Fails

Followed this guide: https://www.youtube.com/watch?v=bqkt6eSsRZs&list=PL_UnIDIwT95NUvLU14l_QFFV2ZxO1phpQ&index=10

Added auth routes from laravel docs

mkdir auth
chmod -R 777 auth

Created login/register views

Created /home route

Customized AuthController:

protected $redirectTo = 'home';
protected $redirectPath = 'home';
protected $loginPath = '/auth/login';

When attempting to access auth/login I got this error:

ErrorException in Request.php line 775: .. Session store not set on
request.

Moved auth routes to middleware group.

Successfully registered, created user in db and sessions file

Changed home route to check is user is logged in:

if(Auth::guest()) {
    return Redirect::to('auth/login');
} else {
    echo "welcome home";
}

Went to auth/logout and then back to home route, was not redirected to login page but to root of site Now whenever I go to auth/login it also redirect me to the root path, so I went to incognito mode and went to the auth/login page, it rendered successfully and logged me in (created a session file in storage/framework/sessions) but then also redirected me to the root path.

From a previous answer I then added this to my auth controller:

public function authenticated( $request,  $user ) {
    return redirect()->intended($this->redirectPath().'?success');
}

Problem still exists when going to home route in normal mode (Chrome) but redirects to auth/login page in incognito mode, and creates session file but still redirects to root path after successful login. I then commented out the authenticated() method in the auth controller but problem still exists...

Previous question: Laravel authentication redirect error

Ad

Answer

If you are using the Laravel 5.2 version then you will need to use web middleware, in my case I have this

Route::group(['middleware' => 'web'], function () {
   Route::auth();
   Route::get('/home', '[email protected]');
});

Where as for version Laravel version 5 and 5.1 you need to have this below routes:

Route::controllers([
'auth' => 'Auth\AuthController'
]);
Ad
source: stackoverflow.com
Ad