title: Firebase will create a new user, but won't return the user object?
body: <p>I'm using Firebase V9 with React. When I fill out the fields below, Firebase will create a new user for me, but it won't return the user object. When I try to <code>console.log(user)</code>, nothing appears. Where am I going wrong here?</p>
  <pre><code>import { React, useState } from 'react';
  import {
    createUserWithEmailAndPassword,
    onAuthStateChanged,
  } from 'firebase/auth';
  import { auth } from '../firebase-config';
  
  function Signup() {
    const [registerEmail, setRegisterEmail] = useState('');
    const [registerPassword, setRegisterPassword] = useState('');
  
    const [user, setUser] = useState({});
  
    onAuthStateChanged(auth, (currentUser) =&gt; {
      setUser(currentUser);
    });
  
    const register = async () =&gt; {
      try {
        const user = await createUserWithEmailAndPassword(
          auth,
          registerEmail,
          registerPassword
        );
        console.log(user);
      } catch (error) {
        console.log(error.message);
      }
    };
  
    return (
      &lt;div className=&quot;min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8&quot;&gt;
        &lt;div className=&quot;sm:mx-auto sm:w-full sm:max-w-md&quot;&gt;
          &lt;a href=&quot;/&quot;&gt;
            &lt;img
              className=&quot;mx-auto h-12 w-auto&quot;
              src=&quot;./img/logo-orange.png&quot;
              alt=&quot;HBD Logo&quot;
            /&gt;
          &lt;/a&gt;
          &lt;h2 className=&quot;mt-6 text-center text-3xl font-extrabold text-gray-900&quot;&gt;
            Sign up for your free account
          &lt;/h2&gt;
          &lt;p className=&quot;mt-2 text-center text-sm text-gray-600&quot;&gt;
            Already have an account?{' '}
            &lt;a
              href=&quot;/signin&quot;
              className=&quot;font-medium text-orange-600 hover:text-orange-500&quot;
            &gt;
              Sign in.
            &lt;/a&gt;
          &lt;/p&gt;
        &lt;/div&gt;
  
        &lt;div className=&quot;mt-8 sm:mx-auto sm:w-full sm:max-w-md&quot;&gt;
          &lt;div className=&quot;bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10&quot;&gt;
            &lt;form className=&quot;space-y-6&quot;&gt;
              &lt;div&gt;
                &lt;label
                  htmlFor=&quot;email&quot;
                  className=&quot;block text-sm font-medium text-gray-700&quot;
                &gt;
                  Email address
                &lt;/label&gt;
                &lt;div className=&quot;mt-1&quot;&gt;
                  &lt;input
                    onChange={(event) =&gt; {
                      setRegisterEmail(event.target.value);
                    }}
                    autoComplete=&quot;email&quot;
                    type=&quot;email&quot;
                    required
                    className=&quot;appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-orange-500 focus:border-orange-500 sm:text-sm&quot;
                  /&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div&gt;
                &lt;label
                  htmlFor=&quot;password&quot;
                  className=&quot;block text-sm font-medium text-gray-700&quot;
                &gt;
                  Password
                &lt;/label&gt;
                &lt;div className=&quot;mt-1 space-y-6&quot;&gt;
                  &lt;input
                    onChange={(event) =&gt; {
                      setRegisterPassword(event.target.value);
                    }}
                    autoComplete=&quot;current-password&quot;
                    type=&quot;password&quot;
                    required
                    className=&quot;appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-orange-500 focus:border-orange-500 sm:text-sm&quot;
                  /&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div&gt;
                &lt;button
                  onClick={register}
                  className=&quot;w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-orange-600 hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500&quot;
                &gt;
                  Sign up
                &lt;/button&gt;
              &lt;/div&gt;
            &lt;/form&gt;
  </code></pre>