firebase / firebase/firebase-js-sdk

browser-back with signInWithRedirect doesn't return control to the calling website

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

Description

### Operating System

all

### Environment (if applicable)

all browsers

### Firebase SDK Version

11.0.1

### Firebase SDK Product(s)

Auth

### Project Tooling

Vercel + Vite + React

### Detailed Problem Description

**Repro Steps**
When using Firebase’s `signInWithRedirect` API with “Option 3: Proxy auth requests to [firebaseapp.com](http://firebaseapp.com/)” from https://firebase.google.com/docs/auth/web/redirect-best-practices , if a user completes the google account selection, goes back in the browser, and then tries to select the account again,

**Expected Behavior**
`https://.firebaseapp.com` should redirect back to the website that called `signInWithRedirect`. Then the website should be able to get the error code the same way it gets other error codes.

```
const firebaseAuth = getAuth();

onAuthStateChanged(firebaseAuth, async (user) => {
try {
const redirectResult = await getRedirectResult(firebaseAuth);
// ...
} catch (error) {
handleAuthError(firebaseAuth, error as FirebaseError);
return;
}
});

async function handleAuthError(auth: Auth | undefined, error: FirebaseError) {
if (error.code === "auth/credential-already-in-use" && auth != null) {
handleAuthCredentialAlreadyInUse(auth, error);
} else if (
// ...
) {
// ...
} else if (error.code === "auth/cancelled-popup-request" || error.code === "auth/popup-closed-by-user") {
// ...
} else {
}
}
```

**Actual Behavior**
Instead of redirecting back to the website that called `signInWithRedirect`, `https://.firebaseapp.com` loads some JS and then a web page that shows the following content.

Image

### Steps and code to reproduce issue

See the problem description

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.