我用的是:"tymon/jwt-auth": "1.0.0-rc.1"
根据官方网站http://jwt-auth.readthedocs.io安装,并且vender:publish完配置文件后,需要按照官网的Update your User model章节配置一下auth所需要的一些类。我第一次用jwt-auth,没有进行按照Update your User model章节进行操作,并且所用的Eloquent也和官网不太一样,遇到了3个问题,在此总结一下:
1、config/auth.php
‘guards‘ => [ ‘api‘ => [ ‘driver‘ => ‘jwt‘, ‘provider‘ => ‘myexample‘, ], ],
结果在此文件下面的 ‘providers‘ 数组中忘记写 ‘myexample‘ 相关的 ‘driver‘ 和 ‘model‘ 了,导致了错误1:
"message": "Type error: Argument 2 passed to Tymon\\JWTAuth\\JWTGuard::__construct() must be an instance of Illuminate\\Contracts\\Auth\\UserProvider, null given, called in ...
问题2和3都是Eloquent Model中遇到的问题,没按照官网Update your User model章节所述导致的,解决办法就是像官网说的改改Auth用到的Model即可,主要是需要Model实现两个接口
2、Model没有实现JWTSubject接口报错:
"message": "Type error: Argument 1 passed to Tymon\\JWTAuth\\JWTGuard::login() must be an instance of Tymon\\JWTAuth\\Contracts\\JWTSubject, instance of App\\Entities\\Authors given, called in ...
3、Model没有实现AuthenticatableContract接口(契约)报错:
"message": "Type error: Argument 1 passed to Tymon\\JWTAuth\\JWTGuard::setUser() must be an instance of Illuminate\\Contracts\\Auth\\Authenticatable, instance of App\\Entities\\Authors given, called in ...
原文地址:https://www.cnblogs.com/SHQHDMR/p/9193216.html
时间: 2024-10-13 06:45:59