2016-03-21 111 views
0

我已经部署了一个larabvel应用程序fortrabbit。已部署的应用程序仅用于测试身份验证和中间件('auth'和'guest')的简单应用程序。我已经尝试在localhost的应用程序,身份验证和中间件工作正常。当我在fortrabbit上试用我的应用程序时,身份验证正常运行,但中间件存在问题。我得到在Fortrabbit重定向循环Laravel 5.1

此网页有重定向循环,ERR_TOO_MANY_REDIRECTS

每次我登录到主页时

routes.php

Route::get('/','[email protected]'); 

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

    Route::get('login','[email protected]'); 
    Route::post('login','[email protected]'); 

    Route::get('register','[email protected]'); 
    Route::post('register','[email protected]ister'); 

}); 

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

    Route::get('home','[email protected]'); 
    Route::get('logout','[email protected]'); 

}); 

Authenticate.php的 '权威性' 中间件:

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的 '客人' 中间件:

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

    return $next($request); 
} 

是否有任何文件/在fortrabbit设置,我必须配置正确运行这个应用程序?

+0

您的认证中间件对我来说很不利。如果guest()这样做,如果没有guest重定向到登录。如果您是不允许客人的页面上的客人,您是否不应该重定向登录?你处于一个无休止的循环中,因为一旦你登录了,你就不再是客人了,所以你会被重定向到'home',这会触发已关闭的'auth'并将你重定向到登录,这会触发重定向你的'guest' ... – sniels

+0

嗨,我认为这是一个会话错误https://github.com/laravel/framework/issues/8172你可以尝试一次干净的安装吗?会场司机在堡兔子里设置了什么? – Gokigooooks

回答

0

源与Fortrabbit内存缓存配置(link)修改config/cache.php后,我们应该改变的不仅是价值CACHE_DRIVER而且SESSION_DRIVERmemcached.env文件

0

您的认证中间件对我来说很不利。
如果guest()这样做,如果没有guest重定向到登录。如果您是不允许客人的页面上的客人,您是否不应该重定向登录?
你处于一个无休止的循环中,因为一旦你登录,你就不再是一个客人,所以你会被重定向到'home',这会触发'auth'关闭并重定向你登录,这会触发'guest'重定向你...

我认为你是权威性中间件应该是这样的,从Laravel on Github

public function handle($request, Closure $next) 
{ 
    if ($this->auth->guest()) { 
     if ($request->ajax()) { 
      return response('Unauthorized.', 401); 
     } else { 
      return redirect()->guest('auth/login'); 
     } 
    } 
    return $next($request); 
} 
+0

我已将else语句更改为'return redirect() - > guest('/ login');'且结果仍然相同 – neemo

+0

@neemo您可以上传Authenticate.php文件,我认为问题是错位托架。 – sniels

+0

我已将更新过的Authenticate.php(上面已更新)重新上传到[mylara.frb.io](http://mylara.frb.io),但仍未解决。 – neemo