title: Create a user programatically using Firebase Auth emulator
body: <p>I am trying to write jest tests using the Firebase Auth emulator and continue to receive the following CORS error.</p>
  <pre class="lang-sh prettyprint-override"><code>console.error
      Error: Headers X-Client-Version forbidden
          at dispatchError (/Users/me/my-project/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:62:19)
          at validCORSPreflightHeaders (/Users/me/my-project/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:99:5)
          at Request.&lt;anonymous&gt; (/Users/me/my-project/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:367:12)
          at Request.emit (events.js:315:20)
          at Request.onRequestResponse (/Users/me/my-project/node_modules/request/request.js:1059:10)
          at ClientRequest.emit (events.js:315:20)
          at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:641:27)
          at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)
          at Socket.socketOnData (_http_client.js:509:22)
          at Socket.emit (events.js:315:20) undefined
  </code></pre>
  <p>The test is very simple:</p>
  <pre class="lang-js prettyprint-override"><code>import { renderHook, act } from &quot;@testing-library/react-hooks&quot;
  import faker from &quot;faker&quot;
  import { useAuth, FirebaseProvider, firebase } from &quot;./index&quot;
  
  
  const wrapper = ({ firebase, children }) =&gt; {
    return &lt;FirebaseProvider firebase={firebase}&gt;{children}&lt;/FirebaseProvider&gt;
  }
  
  const createUser = ({ email = faker.internet.email(), password = faker.internet.password({ length: 6 }) } = {}) =&gt; {
    return firebase
      .auth()
      .createUserWithEmailAndPassword(email, password)
      .then(user =&gt; user)
  }
  
  const signUserIn = ({ email, password } = {}) =&gt; {
    return firebase
      .auth()
      .signInWithEmailAndPassword(email, password)
      .then(user =&gt; user)
  }
  
  describe(&quot;useAuth&quot;, () =&gt; {
    it(&quot;will return the user&quot;, async () =&gt; {
      const { result } = renderHook(() =&gt; useAuth(), { wrapper, initialProps: { firebase } })
      const email = faker.internet.email()
      const password = faker.internet.password()
      await act(async () =&gt; {
        const user = await createUser({ email, password }) // this fails
        await signUserIn({ email, password }) //and so does this
      })
      expect(result.user).toEqual({ email, password })
    })
  })
  </code></pre>
  <p>And for reference, the index file:</p>
  <pre class="lang-js prettyprint-override"><code>const FirebaseProvider = ({ children, firebase }) =&gt; {
    const firestore = firebase.firestore()
    const auth = firebase.auth()
  
    if (useEmulator()) {
      firestore.useEmulator(&quot;localhost&quot;, 8080)
      auth.useEmulator(&quot;http://localhost:9099/&quot;)
    }
  
    const value = { firestore, auth }
  
    return &lt;FirebaseContext.Provider value={value}&gt;{children}&lt;/FirebaseContext.Provider&gt;
  }
  
  const throwError = hook =&gt; {
    throw new Error(`${hook} must be used within a FirebaseProvider`)
  }
  
  const useAuth = () =&gt; {
    const context = useContext(FirebaseContext)
    if (context === undefined) throwError(&quot;useAuth&quot;)
  
    const [user, setUser] = useState()
  
    useEffect(() =&gt; {
      const cleanup = context.auth.onAuthStateChanged(authUser =&gt; {
        authUser ? setUser(authUser) : setUser(null)
      })
      return () =&gt; cleanup()
    })
  
    return { ...context.auth, user }
  }
  </code></pre>
  <p>I have tried using the REST endpoint that the actual emulator uses (below) and it errors in the same way.</p>
  <pre><code>http://localhost:9099/identitytoolkit.googleapis.com/v1/projects/&lt;my-project&gt;/accounts
  </code></pre>
  <p>Is there anyway to get this to run when using jest? Or do I need to create the accounts using the emulator UI, export them and re-import when I am running tests?</p>
  <p>I have found I can use the REST endpoint below to make a user in the test, however it bypasses the emulator and makes a real user.</p>
  <pre><code>https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=&lt;api-key&gt;
  </code></pre>