title: firebase realtime database doesn't work as expected
body: <p>I'm a junior dev, so please be easy with me.</p>
  <p>My goal is to auth an user anonymously when he open the homepage, then if all went ok, he fetch the data from the real time database, but only if the uid match is ok!</p>
  <p>He there are my rules:</p>
  <pre><code>{
    &quot;rules&quot;: {
        &quot;$uid&quot;: {
          &quot;.read&quot;: &quot;auth != null &amp;&amp; auth.uid == $uid&quot;,
          &quot;.write&quot;: &quot;false&quot;,
        }
    }
  }
  
  </code></pre>
  <p>My database is structured like this <a href="https://ibb.co/jkRBCsF" rel="nofollow noreferrer">https://ibb.co/jkRBCsF</a></p>
  <hr />
  <p>The anonymous sign in is on the context</p>
  <pre><code>export const AuthContextProvider = ({ children }: Props) =&gt; {
    React.useEffect(() =&gt; {
      signInAnonymously(auth)
        .then(() =&gt; {
          // Signed in..
        })
        .catch((error) =&gt; {
          const errorCode = error.code;
          const errorMessage = error.message;
          // ...
        });
    }, []);
  
    const values = {};
  
    return &lt;AuthContext.Provider value={values}&gt;{children}&lt;/AuthContext.Provider&gt;;
  };
  </code></pre>
  <p>Then when I open a page for example '/crew' getStaticProps launches fetchPlanetInfo</p>
  <pre><code>export const getStaticProps: GetStaticProps = async () =&gt; {
    const planetInfo = await fetchPlanetsInfo(&quot;destinations&quot;);
  
    return {
      props: {
        data: planetInfo,
      },
    };
  };
  </code></pre>
  <pre><code>export function fetchPlanetsInfo(query: string) {
    let dataArr: any = [];
  
    try {
      onAuthStateChanged(auth, (user) =&gt; {
        if (user) {
          const uid = user.uid;
          const databaseCall = ref(db, uid + &quot;/&quot; + query);
  
          onValue(databaseCall, (snapshot) =&gt; {
            const data = snapshot.val();
            dataArr.push(data);
          });
        } else {
          console.log(&quot;user is signout&quot;);
          // User is signed out
          // ...
        }
      });
    } catch (error) {
      console.log(error);
    }
  
    return dataArr.flat();
  }
  </code></pre>
  <p>I tried to figure out where is the error but I didn't find out the solution</p>
  <p>My problem is that the data is not get from the database. fetchPlanetsInfo return null. I think my rules is written wrong.</p>