2016-04-23 144 views
1

我想在Laravel 5.2實現智威湯遜,但我得到這個錯誤:Laravel JWT驗證錯誤

"message": "call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\\Auth\\TokenGuard' does not have a method 'once'", 
    "status_code": 500, 
    "debug": { 
    "line": 288, 
    "file": "/home/vagrant/Code/lsupport/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php", 
    "class": "ErrorException", 

我的路線文件:

$api = app('Dingo\Api\Routing\Router'); 

$api->version('v1',function($api) 
{ 
    $api->post('login','App\Http\Controllers\Auth\[email protected]'); 
}); 

我AuthController:

public function authenticate(Request $request) 
    { 
     $credentials = $request->only('email','password'); 

     try { 
      if(!$token = JWTAuth::attempt($credentials)) { 
       return $this->response->error(['error' => 'User credentials are not correct!'],401); 
      } 
     } catch(JWTException $ex) { 
      return $this->response->error(['error' => 'Something went wrong!'],500); 
     } 
     return $this->response->item(compact('token')); 
    } 

我正在使用postman進行測試。

回答

3

也有同樣的問題,我通過在config文件夾內的auth.php文件中將默認警衛設置爲'web'來解決它。

'defaults' => [ 
    'guard' => 'web', 
    'passwords' => 'users', 
], 

請記住,您的路由不應該具有此登錄的身份驗證中間件,因爲這僅用於身份驗證。

+0

謝謝!這非常有幫助! – Jamie

+0

也適用於我! –