2016-11-26 132 views
0

我試圖刪除重定向的身份驗證用戶的默認Laravel行爲一旦通過身份驗證。Laravel Ajax登錄嘗試重定向

我評論在LoginController.php

//protected $redirectTo = '/home'; 

而且也改變了AuthenticatesUsers供應商檔案返回,而不是在登錄成功重定向JSON:

protected function sendLoginResponse(Request $request) 
    { 
     $request->session()->regenerate(); 

     $this->clearLoginAttempts($request); 

     /*return $this->authenticated($request, $this->guard()->user()) 
       ?: redirect()->intended($this->redirectPath());*/ 

       return response()->json(['SUCCESS' => 'AUTHENTICATED'], 200); 
    } 

但仍當我成功登錄我看到我的Chrome網絡標籤,我得到一個錯誤,因爲它試圖將我重定向到/home這是一個未定義的路線,導致錯誤,並停止我的Laravel SPA。

爲什麼Laravel繼續引導我到/home,即使我將它註釋掉並更改了Vendor文件?

+0

檢查用戶是否已經驗證過了,並顯示路由的代碼(網頁或API)文件@SummerDeveloper – PassionInfinite

+0

@PassionInfinite用戶進行身份驗證,但路線文件不包含定義對於'home',我評論道:'//路線:: get('home','HomeController @ homepage') - > name('home');' –

+0

您運行了composer命令dump-autoload和config:更改文件後清除? @SummerDeveloper – PassionInfinite

回答

1

這是一箇中間件問題。

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

     return $next($request); 
    } 

在,app/Http/Middleware/RedirectIfAuthenticated.php