title: ReactJS: Fetching GET method with Bearer authorization
body: <p>I have Express API with routes. Now i'm connecting client side to the server.</p>
  
  <p>In React I completed Login request (receiving Bearer token). Now I'm trying to make GET Authorizated request, and I get 401 Unauthorized from the server. From Postman everything is ok. I have CORS extension in google Chrome.</p>
  
  <p>Server Route:</p>
  
  <pre><code>router.get('/tasks', auth, async (req, res) =&gt; {
  try {
      await req.user.populate('tasks').execPopulate()
      res.send(req.user.tasks)
  } catch (e) {
      res.status(500).send()
  }
  </code></pre>
  
  <p>login request which is OK.</p>
  
  <pre><code>handleLogInClick = (email, password) =&gt; {
      console.log("Trying to login ");
  fetch("http://localhost:3000/users/login", {
    // mode: "no-cors",
    method: "POST",
    headers: {
      Accept: "application/json, text/plain, */*",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ email: email, password: password }),
  })
    .then((res) =&gt; res.json())
    .then((data) =&gt;
      this.setState({
        data,
      }),
    );
  this.getTasks("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9");
  </code></pre>
  
  <p>};</p>
  
  <p>I know the token, so I tried to get response from the server passing him to the function. I tried some options in headers, but i failed.
  The metod getTasks, whih has 401 error below</p>
  
  <pre><code>getTasks = (token) =&gt; {
  token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZGNmZjFhMjQzZWUwNTJmNmNkMjAzYzgiLCJpYXQiOjE1NzM5ODEwODV9.qUY8RCpc6ABRX7qPw_ea8lKaFg9xDRw2fkiVne1L-s4";
  
  fetch("http://localhost:3000/tasks", {
    method: "GET",
    mode: "no-cors",
    headers: {
      Accept: "application/json, text/plain, */*",
      // "Content-Type": "application/json",
      Authorization: "Bearer " + token,
    },
  })
    .then((res) =&gt; res.json())
    .then(
      (tasks) =&gt;
        this.setState({
          tasks,
        }),
      console.log(token),
    );
  </code></pre>
  
  <p>};</p>
  
  <p>request from Postman with options:</p>
  
  <p>GET /tasks HTTP/1.1
  Host: localhost:3000
  : ,
  Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZGNmZjFhMjQzZWUwNTJmNmNkMjAzYzgiLCJpYXQiOjE1NzM5ODEwODV9.qUY8RCpc6ABRX7qPw_ea8lKaFg9xDRw2fkiVne1L-s4
  User-Agent: PostmanRuntime/7.19.0
  Accept: <em>/</em>
  Cache-Control: no-cache
  Postman-Token: b209d7ee-e254-4594-9616-93ebc86bea99,8e867f14-1d0e-40b5-8f85-76a0d317af84
  Host: localhost:3000
  Accept-Encoding: gzip, deflate
  Connection: keep-alive
  cache-control: no-cache</p>
  
  <p>Thanks in advance for Your help.</p>