Flutter Web firebase_auth signin with google 'Access-Control-Allow-Credentials' header in the response is '' (empty)

Viewed 351

I try to run Flutter Web with firebase_auth and sign in with google but i'm getting : 'Access-Control-Allow-Credentials' header in the response is '' (empty)

I'm using

google_sign_in: ^4.1.4
firebase_auth: ^0.15.5+2
firebase_core: ^0.4.4+2

method for login is:

Future<FirebaseUser> handleSignIn() async {
    final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
    final GoogleSignInAuthentication googleAuth = await googleUser.authentication;

    final AuthCredential credential = GoogleAuthProvider.getCredential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );

    user = (await _auth.signInWithCredential(credential)).user;
    print("signed in " + user.displayName);
    return user;
  }

I have configgured web app in firebase console and added config to web/index.html :

  <script src="https://www.gstatic.com/firebasejs/7.9.3/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.9.3/firebase-analytics.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.9.3/firebase-auth.js"></script>

  <script>
    // Your web app's Firebase configuration
    var firebaseConfig = {
      apiKey: ...,
      authDomain: ...,
      databaseURL: ...,
      projectId: ...,
      storageBucket: ...,
      messagingSenderId: ...,
      appId: ...,
      measurementId: ...
    };
    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
    firebase.analytics();
  </script>
  <script src="main.dart.js" type="application/javascript"></script>

But when i'm calling it first it shows me to select account but after that it returns with error:

FirebaseError: A network error (such as timeout, interrupted connection or unreachable host) has occurred. (auth/network-request-failed)

And in console from Chrome i can see:

    Access to fetch at 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?..' 
    from origin 'https://...firebaseapp.com' has been blocked by 
    CORS policy: Response to preflight request doesn't pass access 
control check: The value of the 'Access-Control-Allow-Credentials' header in the 
response is '' which must be 'true' when the request's credentials mode is 'include'.

I tested the app on Android and it login just fine.

1 Answers

I had a rewrites section in my firebase.json file.

"rewrites": [
  {
    "source": "**",
    "destination": "/index.html"
  }
]

I think that was rewriting the authentication url too? Once I removed that, authentication worked for me.

Related