I got an error on login attempt:
"Argument 1 passed to Tymon\JWTAuth\JWTAuth::fromUser() must be an instance of Tymon\JWTAuth\Contracts\JWTSubject, instance of App\User given, called in /vendor/tymon/jwt-auth/src/JWTAuth.php on line 84 and defined"
// grab credentials from the request
$credentials = $request->only('email', 'password');
try {
// attempt to verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(compact('token'));
I am using the 0.6.*-dev package with Sentinel provider.
The user model needs to implement Tymon\JWTAuth\Contracts\JWTSubject in the new version. This is where you define the subject claim, and any custom claims
Well, it works fine now. Thanks!
<?php
namespace App;
use Cartalyst\Sentinel\Users\EloquentUser;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends EloquentUser implements JWTSubject
{
/**
* Get the identifier that will be stored in the subject claim of the JWT
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getUserId();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
}
:+1:
thanx, man
Thanx, man i solve my problem
Most helpful comment
Well, it works fine now. Thanks!