运行php artisan route:安装了jwt的列表时出现问题

时间:2018-11-17 00:57:09

标签: php laravel jwt jwt-auth

我已经遵循了本教程 https://tutsforweb.com/restful-api-in-laravel-56-using-jwt-authentication/ 而且工作正常, 但是当我尝试运行

  
    

php artisan route:list

  

我收到此错误,

  Tymon\JWTAuth\Exceptions\JWTException  : The token could not be parsed from the request

  at F:\My_Projects\Laravel\api-laravel-jwt\vendor\tymon\jwt-auth\src\JWT.php:185
    181|      */
    182|     public function parseToken()
    183|     {
    184|         if (! $token = $this->parser->parseToken()) {
  > 185|             throw new JWTException('The token could not be parsed from the request');
    186|         }
    187|
    188|         return $this->setToken($token);
    189|     }

  Exception trace:

  1   Tymon\JWTAuth\JWT::parseToken()
      F:\My_Projects\Laravel\api-laravel-jwt\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:223

  2   Illuminate\Support\Facades\Facade::__callStatic("parseToken", [])
      F:\My_Projects\Laravel\api-laravel-jwt\app\Http\Controllers\ProductController.php:14

  Please use the argument -v to see more details.

我一直在努力解决这个问题,但没有成功,有帮助吗?

这是带有我的代码的github存储库:-

https://github.com/Imohamedgabr/laravel-5.7-jwt-starter

1 个答案:

答案 0 :(得分:1)

在产品控制器中的这一部分:-

public function __construct()
{
    $this->user = JWTAuth::parseToken()->authenticate();
}

它调用解析令牌,这就是为什么它转到jwt auth解析令牌并在那里失败的原因。 因此,虽然没有提供经过身份验证的用户,但失败了。 希望这会有所帮助。