Reputation: 273
My user model:
namespace Modules\Settings\Entities;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Users extends Authenticatable
{
Protected $table="user";
// protected $primaryKey = 'id';
protected $fillable = ['id','username','password','user_status_type_id','client_id','created_userid'];
protected $hidden = [
'password', 'remember_token',
];
}
In the controller I have:
public function login(Authentication $request){
$credentials = $request->only('username', 'password');
try {
// verify the credentials and create a token for the user
$token = JWTAuth::attempt($credentials);
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong
return response()->json(['error' => 'could_not_create_token'], 500);
}
// if no errors are encountered we can return a JWT
return response()->json(compact('token'));
}
I have used Hash::make($data->password) when creating the user.When I test it in Postman I always get "invalid credential"
Upvotes: 0
Views: 1677
Reputation: 574
if you are using version 0.5.* and kept the default settings as per the documentation, the JWTAuth::attempt($credentials)
part will look for the input values 'email' and 'passowrd' $request->only('email', 'password');
In your case you are using $request->only('username', 'password');
Upvotes: 1