title: Validating authorized & Unauthorized User (JWT ReactJS-Laravel)
body: <p>I'm currently doing login page. I have a problem with how to check if the user I login is valid or invalid before I set the token to the local storage.</p>
  <p><strong>Error to my console:</strong></p>
  <blockquote>
  <p>POST http://localhost:8000/api/auth/login 401 (Unauthorized)</p>
  </blockquote>
  <blockquote>
  <p>Uncaught (in promise) Error: Request failed with status code 401</p>
  </blockquote>
  <p><strong>My Goal:</strong>
  To redirect to other pages if the user is valid then if invalid the user who enters will remain on the login page.</p>
  <p><strong>I use Axios.post to make a request</strong></p>
  <p><strong>I have here the handleSubmit button:</strong></p>
  <pre><code>handleSubmit(e) {
      e.preventDefault();
  
      axios.post('/api/auth/login',this.state).then(response =&gt; {
          const token_id = response.data.access_token;
          const responsed = response.data;
          // localStorage.setItem('token', token_id);
          console.log(responsed);
      });
  
     
  
  }
  </code></pre>
  <p><strong>And this is my function which is default from JWT documentation:</strong></p>
  <pre><code>public function login(Request $request)
  {
      $credentials = $request-&gt;only('email', 'password');
  
      if ($token = $this-&gt;guard()-&gt;attempt($credentials)) {
          return $this-&gt;respondWithToken($token);
      }
  
      return response()-&gt;json(['error' =&gt; 'Unauthorized'], 401);
  }
  </code></pre>