I tried to follow the unfinished docs for 1.0.*
When I try to login I always get this error:
Type error: Argument 1 passed to Tymon\JWTAuth\JWTGuard::login() must be an instance of Tymon\JWTAuth\Contracts\JWTSubject, instance of App\User given, called in /Users/ricardolobo/Sites/backend/vendor/tymon/jwt-auth/src/JWTGuard.php on line 124
I'm using Laravel 5.5 and PHP 7.1
I "solved" this by removing JWTSubject type hinting on the following files:
vendor/tymon/jwt-auth/src/JWT.php
vendor/tymon/jwt-auth/src/JWTGuard.php
@ricardo-lobo did you read the quick-start guide?
http://jwt-auth.readthedocs.io/en/docs/quick-start/
There's an item called "Update your User model" with the following code:
class User extends Authenticatable implements JWTSubject
This should solve that error you got.
Make sure if you move your User model into say App\Models\User that you update the config/auth model:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
I made this mistake... few hours of debugging. :)
Usually it is due to Tymon\JWTAuth\Contracts\JWTSubject which needs to be added in User Model. Also as JWTSubject implements in the User model, JWTSubject methods must be declared inside the model as below. After that BINGO !! you will get token as expected.
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
I have a separate table(not users table) handling merchant authentication for my app. So I'm using laravel query builder. Here's the error I got
Type error: Argument 1 passed to Tymon\JWTAuth\JWT::fromUser() must be an instance of Tymon\JWTAuth\Contracts\JWTSubject, instance of stdClass given
did you implements JWTSubject in User Model?
class User extends Authenticatable implements JWTSubject
Most helpful comment
@ricardo-lobo did you read the quick-start guide?
http://jwt-auth.readthedocs.io/en/docs/quick-start/
There's an item called "Update your User model" with the following code:
class User extends Authenticatable implements JWTSubjectThis should solve that error you got.