title: Right way to keep Firebase user data and session stored - React Native
body: <p>I have been looking on several ways to keep the user logged in my react native application. One of those are:</p>
  <pre><code>auth.onAuthStateChanged((user) =&gt; {
         if (user) {
           setIsAuthenticated(true);
         } else {
           setIsAuthenticated(false);
         
   });
  </code></pre>
  <p>Which isn't working for me, whenever I press <code>r</code> on the application to hot refresh, it losses the user. <br>
  I'm currently storing the user <code>email</code>, <code>uid</code> on the local storage, and only loggin it out whenever he presses the logout button. Is this the right way to do so? I have encountered some problems, for example. I can't use <code>auth().currentUser</code> since the data is stored in async storage.<br>
  This is how i'm managing it:</p>
  <pre><code>
  export default function App() {
    // Autentication
    const [isAuthenticated, setIsAuthenticated] = useState(false);
  
    // Dark mode
    const [darkMode, setDarkMode] = useState(false);
  
    // Setting location
    let [locale, setLocale] = useState(Localization.locale);
    i18n.fallbacks = true;
    i18n.translations = { en, pt };
    i18n.locale = locale;
  
    // Settings fonts
    const [fontsLoaded] = useFonts({
      Roboto_400Regular,
      Roboto_500Medium,
      Roboto_700Bold,
    });
  
    useEffect(() =&gt; {
      setLocale('pt');
  
      getData('@rememberUser')
        .then((data) =&gt; data &amp;&amp; setIsAuthenticated(true))
        .catch(() =&gt; console.log('No user on async'));
  
      // auth.onAuthStateChanged((user) =&gt; {
      //   if (user) {
      //     setIsAuthenticated(true);
      //   } else {
      //     setIsAuthenticated(false);
      //   }
  
      //   console.log(user);
      // });
    }, []);
  
    if (!fontsLoaded) return &lt;&gt;&lt;/&gt;;
  
    return (
      &lt;DataProvider
        setIsAuthenticated={setIsAuthenticated}
        setDarkMode={setDarkMode}
        darkMode={darkMode}
      &gt;
        &lt;ThemeProvider theme={darkMode ? darkTheme : lightTheme}&gt;
          {!isAuthenticated ? (
            &lt;NavigationContainer&gt;
              &lt;AuthRoutes /&gt;
            &lt;/NavigationContainer&gt;
          ) : (
            &lt;Provider store={store}&gt;
              &lt;Main /&gt;
            &lt;/Provider&gt;
          )}
          &lt;ToastMessage /&gt;
        &lt;/ThemeProvider&gt;
      &lt;/DataProvider&gt;
    );
  }
  </code></pre>
  <p>storing:</p>
  <pre><code>async function storeData(value: any) {
    try {
      await clearAll();
      const jsonValue = JSON.stringify(value);
      await AsyncStorage.setItem('@rememberUser', jsonValue);
    } catch (error) {
      console.log('Error on async storage');
    }
  }
  </code></pre>
  <p>Is this the right way to keep track of the user?</p>