title: How to fix 401 (Unauthorized) for a login request
body: <p>I'm getting a 401 error for my login requests using JWT authentication, on the signup page it's working great and it creates the user in database, but the login is not working.
  I really dunno which code to include so feel free to for the needed code.</p>
  
  <p>I verified that entered credentials already exists in the database</p>
  
  <p>login.ts</p>
  
  <pre><code>export class LoginComponent {
  
    public form={
  em:null,
  pass:null
    };
    public error = null;
      constructor(private http :HttpClient) { 
  
      }
  Submit(){
      this.http.post('http://localhost:8000/api/login',this.form).subscribe(
        data =&gt; console.log(data),
        error =&gt; console.log(error)
      );
  
    }
      }
  </code></pre>
  
  <p>api.php</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  
  Route::group([
  
      'middleware' =&gt; 'api',
  
  
  ], function () {
  
      Route::post('login', 'AuthController@login');
  });
  
  </code></pre>
  
  <p>login function</p>
  
  <pre class="lang-php prettyprint-override"><code>public function login()
      {
          $credentials = request(['email', 'password']);
  
          if (! $token = auth()-&gt;attempt($credentials)) {
              return response()-&gt;json(['error' =&gt; 'user does not exist'], 401);
          }
  
          return $this-&gt;respondWithToken($token);
      }
  </code></pre>