2016-03-21 57 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