user authentication in laravel using jwt code example
Example 1: laravel JWTAuthentication
$ composer require tymon/jwt-auth:dev-develop --prefer-source
Example 2: jwt auth laravel auth without password field
public function authenticate(Request $request) {
$email = $request->input('email');
$user = User::where('email', '=', $email)->first();
try {
if (! $token = JWTAuth::fromUser($user)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
return response()->json(['error' => 'could_not_create_token'], 500);
}
return response()->json(compact('token'));
}