Open ricardo-lobo opened 6 years ago
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
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
thanks,i take it and look solve problem good job
@rafaelrenanpacheco's solution worked for me class User extends Authenticatable implements JWTSubject
Replace from : 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
TO,
'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\User::class, ],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
It's Work for me.
Hi, i solved this with the comment of the person who said "Did you read the quick-start guide?". I ilterally copy this "class User extends Authenticatable implements JWTSubject"(the extend part is the important thing) into my User model class and it solved the problem, ty.
@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.
It's working now, 💯 thanks 👍🏻
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