Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Auth State Persistence not working as expected with React + Vite #8626

Open
dpschramm opened this issue Nov 2, 2024 · 3 comments
Open

Comments

@dpschramm
Copy link

Operating System

macOS 14.5 (23F79)

Environment (if applicable)

Chrome 129.0.6668.60 (arm64), Vite 5.4.10, React 18.3.1

Firebase SDK Version

11.0.1

Firebase SDK Product(s)

Auth

Project Tooling

React app built with Vite

Detailed Problem Description

I expected auth state to persist by default as I am creating a web app with React and Vite. However, the auth state is cleared on page refresh.

I am accessing the auth state using onAuthStateChanged(). It never fires an event with a non-null user by default.

Setting the persistence setting fixes this:

const firebaseAuth = initializeAuth(firebaseApp, {
    persistence: [browserLocalPersistence]
});

I'm filing this bug as the default behaviour does not match the documentation in: https://firebase.google.com/docs/auth/web/auth-state-persistence#web

Steps and code to reproduce issue

  1. Create a new React app using Vite
  2. Attempt to read previous auth state using onAuthStateChanged()

Expected: receive an onAuthStateChanged() callback with a valid user, if the user was previously signed in.

Observed: never receive an onAuthStateChanged() callback with a valid user. Setting persistence manually during initializeAuth fixes this.

@dpschramm dpschramm added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Nov 2, 2024
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jbalidiong jbalidiong added api: auth needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Nov 4, 2024
@DellaBitta
Copy link
Contributor

Hi @dpschramm,

Unfortunately we couldn't reproduce this issue. We've created an verifiable example here. Could you alter it to reproduce the issue that you're seeing and let us know what the required changes are? Thanks!

@google-oss-bot
Copy link
Contributor

Hey @dpschramm. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants