firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.01k stars 932 forks source link

Auth emulator resets anonymous auth when restarted #5278

Open pkaminski opened 1 year ago

pkaminski commented 1 year ago

[REQUIRED] Environment info

firebase-tools: 11.16.0

Platform: Windows

[REQUIRED] Test case

Set up a new project with the auth emulator enabled, and a web client that calls app.auth().signInAnonymously().

[REQUIRED] Steps to reproduce

  1. Start the auth emulator.
  2. Sign in from the web client. Note the uid of the user that was created.
  3. Reload the client and note that the uid of the (anonymous) user remains the same.
  4. Stop the auth emulator.
  5. Start the auth emulator.
  6. Reload the client and observe the uid of the user.

(Setting the emulator to export/import data doesn't affect the outcome.)

[REQUIRED] Expected behavior

The uid should remain the same if signInAnonymously() is called from the same browser, and the local state (IndexedDB, etc.) hasn't been cleared.

[REQUIRED] Actual behavior

A new user with a fresh uid is created. You can observe that the POST to http://localhost:9099/www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key=demo-dev with the stored idToken fails with error code 400, causing a request to signupNewUser to be issued.

It's not clear whether this is expected behavior or not, but it doesn't match the behavior in production and makes it hard (impossible?) to keep a consistent anonymous user identity when testing in dev over a longer period of time.

jbaptisteroesch commented 1 year ago

firebase-tools: 11.19.0

The issue concerns the app.auth().signInAnonymously() function but at least also auth.signInWithEmailAndPassword(). You can find here a link to a reproducible code.

Steps to reproduce

  1. Start the auth emulator.
  2. Create a user with the email test@pm.me and the password aaaaa2.
  3. Run the project and click the log-in button.
  4. Refresh the page.
  5. The user is logout; the console displays an error code 400, and the FirebaseAuth.instance.currentUser is null.

Expected behavior The user stays logged in, as in the production environment.

It's clearly an unexpected behavior as the comportment is different between the production and the dev environment.