Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

auth/popup-closed-by-user error 2 seconds after signInWithPopup

I am using firebase auth to authenticate users and do things on their behalf. I had this working before, and am having trouble figuring out what's going on now.

I'm using the example from the documentation almost unchanged:

import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";
import { initializeApp } from "firebase/app";

const firebaseConfig = {
  // ...
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);

export function signIn() {
  const provider = new GoogleAuthProvider();
  provider.addScope('https://www.googleapis.com/auth/contacts.readonly');

  console.log('before sign in');
  signInWithPopup(auth, provider)
    .then((result) => {
      console.log('success!');

      const credential = GoogleAuthProvider.credentialFromResult(result);
      const token = credential.accessToken;

      const user = result.user;
      console.log(token, user);
    }).catch((error) => {
      console.error(error.code);
    });
}

document.addEventListener('click', ()=>signIn());

When I click in the page, this is what happens:

  1. The authentication popup opens and the 'before sign in' log is triggered
  2. Wait for ~2 seconds
  3. signInWithPopup throws a auth/popup-closed-by-user error
like image 866
bastien girschig Avatar asked Oct 21 '25 06:10

bastien girschig


2 Answers

The issue was related to these HTTP headers I configured on my server:

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

I added these when I was experimenting with SharedArrayBuffer. Removing them fixed the issue.

like image 103
bastien girschig Avatar answered Oct 25 '25 12:10

bastien girschig


For me, I had this error on iOS Emulator if I tried to put this into the Info.plist

<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
like image 20
Anh Nguyen Avatar answered Oct 25 '25 12:10

Anh Nguyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!