title: Gets 401 error while user tries to do Fetch Get request after authentication
body: <p>I'm trying to get user details after user looged in but user is getting 401 error even user is looged in with 200 ok.</p>
  <ul>
  <li>Explanation of process:</li>
  <li>i have logged in user using fetch post request.</li>
  <li>stored username,role,staffid to async storage</li>
  <li>now i want to list all user (with <code>/api/staff</code>  endpoint response throws user firstname and last name )with fetch get request but whenever i make <code>GET</code> request it
  throws <code>401</code> error.
  It will be lifesaver to crack this step for me,thank you!</li>
  </ul>
  <p>here is my code</p>
  <pre><code>import AsyncStorage from &quot;@react-native-community/async-storage&quot;;
  import React, { useState, useEffect } from &quot;react&quot;;
  
  import { SafeAreaView, Text, StyleSheet, Alert } from &quot;react-native&quot;;
  import AuthService from &quot;../api/auth-service&quot;;
  import BASE_URL from &quot;../api/baseUrl&quot;;
  
  export default function HomeScreen(props) {
    const [firstName, setFirstName] = useState({});
    const [lastName, setLastName] = useState({});
  
    const [userValue, setUserValue] = useState({});
  
    useEffect(() =&gt; {
      let mounted = true;
      if (mounted) {
        getDataFromStorage();
        getUserInfo();
      }
      return () =&gt; {
        mounted = false;
      };
    }, []);
  
    const getDataFromStorage = async () =&gt; {
      let user = await AsyncStorage.getItem(&quot;LoggedInUser&quot;);
      setUserValue(JSON.parse(user));
    };
  
         const getUserInfo=async()=&gt;{
    return fetch(BASE_URL+&quot;/api/staff&quot;)
    .then((response) =&gt; { 
      if(response.ok){
      console.log(response);
      }else{
        console.log(response.status);
        
      }
    })
    .catch((error) =&gt; {
      console.log(error);
      this.setState({ errorMsg: &quot;Error retreiving data&quot; });
    });
  }
  
   return (
      &lt;SafeAreaView&gt;
        &lt;Text&gt;
          {&quot;Good morning &quot; + userValue.username + &quot;  &quot;}
          {&quot;you role is  &quot; + userValue.role +&quot;your staff id is &quot; + userValue.staffId+&quot; &quot; + &quot;your first name is &quot;+ firstName +&quot;this is your last name&quot;+lastName} 
        &lt;/Text&gt;
      &lt;/SafeAreaView&gt;
    );
  }
  </code></pre>
  <p>authservice.js</p>
  <pre><code>import AsyncStorage from &quot;@react-native-community/async-storage&quot;;
  import BASE_URL from &quot;./baseUrl&quot;;
  
  class AuthService {
    login(Username, Password, role) {
      console.log(Username, role);
  
      return fetch(BASE_URL + &quot;/api/authentication/login&quot;, {
        method: &quot;POST&quot;,
        headers: {
          Accept: &quot;application/json&quot;,
          &quot;Content-Type&quot;: &quot;application/json&quot;,
        },
        
        body: JSON.stringify({
          Username,
          Password,
        }),
      }).then((res) =&gt; {
        if (res.ok) {
          console.log(&quot;the login response&quot;, res);
          return res.json();
        } else {
          alert(&quot;Invalid Username or Password&quot;);
          window.stop();
        }
      });
    }
  
    logout() {
      AsyncStorage.getAllKeys().then((keys) =&gt; AsyncStorage.multiRemove(keys));
        }
  }
  export default new AuthService();
  </code></pre>
  <p>login.js</p>
  <pre><code>const submitData = async () =&gt; {
   AuthService.login(Username, Password).then(
        (data) =&gt; {
          console.log(JSON.stringify(data));
          AsyncStorage.setItem(&quot;LoggedInUser&quot;, JSON.stringify(data));
          if (data.role == &quot;Admin&quot;) {
            console.log(data.username);
            navigation.navigate(&quot;adminPage&quot;);
          } else {
            navigation.navigate(&quot;staffpage&quot;);
          }
        },
        (error) =&gt; {
          Alert.alert(error);
        }
      );
    };
  </code></pre>