firebase / firebase/firebase-js-sdk

Unexpected sign out when using local storage persistence and fallbackToPolling = true

Open
#9,471 3 comments 0 reactions 0 assignees View on GitHub
api: auth needs-attention question Repro Needed stack:React
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### Operating System

iOS (mostly)

### Environment (if applicable)

mobile

### Firebase SDK Version

12.7.0

### Firebase SDK Product(s)

Auth

### Project Tooling

React app Vite

### Detailed Problem Description

- At my company we use firebase for authentication. We have around 100,000 distinct users that go through some sort of auth every week.
- We received some reports that our magic link flow was not working intermittently. Folks would click the link but instead of being signed in automatically as expected they would hit our login screen.
- After adding extensive logging we realized people encountering this issue _were_ being signed in but immediately after their sign in we received an event from `onIdTokenChanged` with a null user.
- Our logs indicated that this trigger of `onIdTokenChanged` with null user didn't originate from our own code.
- Additionally logs indicate this trigger of `onIdTokenChanged` doesn't result from a window storage event (we're using BrowserLocalStorage persistence).
- Digging into the firebase sdk code we noticed there's a fallback polling mechanism [here](https://github.com/firebase/firebase-js-sdk/blob/c4a3a5643b79a2165d8b38d35734053dcce8d224/packages/auth/src/platform_browser/persistence/local_storage.ts#L56).
- After disabling this fallback via a patch the problem of some users being signed out randomly stopped. Previously this was happening to around 700 folks every week.
- The polling fallback appears to be for old mobile browser we don't need to support.
- The intermittent problems here indicate that there is likely some sort of subtle and rare race condition in the polling code.

### Steps and code to reproduce issue

Unfortunately we were unable to reproduce the issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.