I'm currently implementing JWT in my project to support an API of sorts. This API is only available for a specific model. This model works correctly using the custom guard I've declared when I want to log it in, I've ensured the contracts and authenticatable traits have been properly applied, yet the ->byId method always fails. Here's my code:
namespace App;
class Customer extends Model implements Authenticatable {
use \Illuminate\Auth\Authenticatable;
In my jwt.php file, I've told it to use my custom model:
'user' => \App\Customer::class,
When I execute:
JWTAuth::fromUser($customer);
I receive a proper token.
I then use Postman to check this by passing it with the Authorization: Bearer <token> header. The token is correctly set.
For subsequent requests to my protected route, I then attempt to authenticate the user in this way:
$token = JWTAuth::parseToken()->authenticate();
->authenticate() always fails.
The reason it fails is due to this:
if (! $this->auth->byId($id)) {
return false;
}
This always returns false.
However, resolving the id from the $id = $this->getPayload($token)->get('sub'); call does provide me with the valid ID for this particular Customer. Further, the model is actually a traditional model, where the PK is the id column, and my identifier is set correctly:
'identifier' => 'id',
Why is the EloquentUserAdapter not able to resolve an instance of my Customer?
I've scoured Google and have attempted a variety of fixes, but nothing has come to fruition. Any help would be greatly appreciated.
Update
I've dumped the SQL query that was executed, and the table it attempts to reference is my default User model, it is not my custom model. Why is that?
Update 2
The tymon.jwt.provider.user singleton bound to the UserInterface correctly references my custom model:
return $app['tymon.jwt.provider.user'];
Provides:
EloquentUserAdapter {#849
#user: Customer {#850
#primaryKey: "id"
#table: "customers"
Update 3
In booting the JWT User provider, it knows which model I want to use:
$model = $app->make($this->config('user'));
Yields:
Customer {#1040
#primaryKey: "id"
#table: "customers"