I am creating a backend of my app using laravel with jwt aunthetication and i keep getting this error "user not found" whenever i send a get request to my auntheticated route, i did not change the custom 'id' for the user...how can i solve this error?
here are the api routes
api.php
`Route::post('/user', ['uses'=>'userController@signup']);
Route::post('/user/signin', ['uses'=>'userController@signin']);
Route::group(['middleware' => 'jwt.auth'], function () {
Route::post('/saccosGroup', ['uses'=>'saccosController@postsaccos']);
Route::get('/saccosGroups', ['uses'=>'saccosController@getsaccosGroups']);
}); `
jwt.php
`
'user' => 'App\User',
'identifier' => 'id',
`
User Modal
user.php
`class User extends Authenticatable
{ protected $table ='users';
protected $primaryKey = 'id';
protected $fillable = [
'name', 'email', 'password', 'phone'
];
protected $hidden = [
'password', 'remember_token',
];
}`
You may have wrong auth guard for checking user. Share controller file to get more details.
Moreover, you can follow following guide to configure Laravel auth with JWT token.
http://www.expertphp.in/article/api-authentication-using-jwt-in-laravel-5-4-tutorial-with-example
Thanks.
@fideliscode
I was having this same problem for a few hours. I'm making a backend app with Lumen 5.6
It would have helped to see your userController@signup method.
I assume you were not hashing your password for the User, apparently when you do \Tymon\JWTAuth\JWTAuth::attempt(), it's expecting to validate against a Hashed password from the Users database table.
Meaning you pass a plain text password in the POST request, \Tymon\JWTAuth\JWTAuth::attempt() hashes it and then compare it with the hashed one in the database.
I started hashing my Users password with \Illuminate\Support\Facades\Hash::make(), and I was able to get a token back from the "login" request as expected.
For the sake of others who always fall to "user_not_found" error, make sure that your password is hashed using password_hash PHP function or \Illuminate\Support\Facades\Hash::make($mypassword). I experienced that error, traced down to the ocean floor to find that the default BcryptHasher#check() method executes password_verify() PHP function. Pain in the ass!
ref: https://iwader.co.uk/post/tymon-jwt-auth-with-lumen-5-2#comment-3043800893
Most helpful comment
@fideliscode
I was having this same problem for a few hours. I'm making a backend app with Lumen 5.6
It would have helped to see your
userController@signupmethod.I assume you were not hashing your password for the
User, apparently when you do\Tymon\JWTAuth\JWTAuth::attempt(), it's expecting to validate against a Hashed password from the Users database table.Meaning you pass a plain text password in the POST request,
\Tymon\JWTAuth\JWTAuth::attempt()hashes it and then compare it with the hashed one in the database.I started hashing my Users password with
\Illuminate\Support\Facades\Hash::make(), and I was able to get a token back from the "login" request as expected.ref: https://iwader.co.uk/post/tymon-jwt-auth-with-lumen-5-2#comment-3043800893