Search code examples
phplaravellaravel-5fortrabbit

Redirect Loop Laravel 5.1 in Fortrabbit


I have deployed a laravel app to fortrabbit. The deployed app is a simple app just to test authentication and middleware ('auth' and 'guest'). I have tried the app in localhost, the authentication and middleware worked fine. When I tried my app in fortrabbit, the authentication worked properly but there was an issue with the middleware. I get

This webpage has a redirect loop, ERR_TOO_MANY_REDIRECTS

every time I log into the home page.

routes.php:

Route::get('/','UserController@getIndex');

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

   Route::get('login','UserController@getLogin');
   Route::post('login','UserController@postLogin');

   Route::get('register','UserController@getRegister');
   Route::post('register','UserController@postRegister');

});

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

   Route::get('home','MainController@getHome');
   Route::get('logout','MainController@logout');

});

Authenticate.php for 'auth' middleware:

public function handle($request, Closure $next)
{

    if ($this->auth->guest()) {
        if ($request->ajax()) {
            return response('Unauthorized.', 401);
        } else{
            return redirect()->guest('/login');
    }

    return $next($request);
}

RedirectIfAuthenticated.php for 'guest' middleware:

public function handle($request, Closure $next)
{
    if ($this->auth->check()) {
        return redirect('home');
    }

    return $next($request);
}

Is there any file/setting in fortrabbit that I have to configure to run this app properly?


Solution

  • After modifying config/cache.php with Fortrabbit memcache configuration (link), we should change not only the value of CACHE_DRIVER but also the SESSION_DRIVER to memcached in .env file