firebase / firebase/firebase-js-sdk

FR: There is no way to know quickly if firebase is processing a login redirect

Open
#6,607 1 comment 2 reactions 0 assignees View on GitHub
api: auth feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### [REQUIRED] Describe your environment

* Operating System version: macOS 12.5.1
* Browser version: Brave 1.43.93
* Firebase SDK version: 9.9.4
* Firebase Product: auth

### [REQUIRED] Describe the problem

Firebase does not expose a functionality that allows us to know right away if the user is coming from a login redirect or not (using `signInWithRedirect`).

There is of course `getRedirectResult` which can tell us that, but only after we have waited that the promise resolves, which can take x seconds.

This prevents us from correctly showing a progress bar/loading indicator.

What we would need is something like `isSignInRedirected: boolean`. Then it would be possible to do something like this:

```javascript
if(auth.isSignInRedirected) {
this.showLoadingBar()

const result = await getRedirectResult(auth) // can take a couple of seconds

this.hideLoadingBar()

// do something with results
}
```

Right now, I have found a non-official solution, but like all non-official solutions, it is very brittle as it may change at any moment. Firebase stores this localstorage key for a brief moment at redirect: "firebase:pendingRedirect:{someId}:[DEFAULT]". By checking if this key is available at application load, you can know right away if there is a pending redirect.

Perhaps Firebase could expose a method that checks on this key for us.

This is related to https://github.com/firebase/firebase-js-sdk/issues/595, but unfortunately, it has been locked and closed

---
Edit

I have looked all all the events `onAuthStateChanged`, `onIdTokenChanged`, `beforeAuthStateChanged`, but they take just as much time to report something as `getRedirectResult`.

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.