I have a web app developed in HTML, JS with server side backend by Express.js and Firebase SDK client via CDN.
Adding Google Auth Provider for users sign in I got the error ‘Requested action is invalid’ when the user click on login button that is connected to my js function with signInWithPopup from firebase sdk.
I’m working on localhost development environment but in firebase console ‘localhost’ is already configured for authorized domains.
I got the error when click function is executed and redirect to my firebase project with google sign in option.
My code:
import { GoogleAuthProvider, signInWithPopup } from "https://www.gstatic.com/firebasejs/9.19.1/firebase-auth.js";
document.addEventListener('DOMContentLoaded', function(){
const provider = new GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/contacts.readonly')
document.getElementById('login-btn').addEventListener('click', function() {
signInWithPopup(window.auth, provider)
.then((result) => {
/** @type {firebase.auth.OAuthCredential} */
var credential = result.credential;
// This gives you a Google Access Token. You can use it to access the Google API.
var token = credential.accessToken;
// The signed-in user info.
var user = result.user;
// IdP data available in result.additionalUserInfo.profile.
// ...
}).catch((error) => {
console.log(error)
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
})
})
I have found a lot of same question about this problem but all of them talk about authorized domain. I already checked and my authorized domain seem to be correctly configured because I have localhost and 2 domain app domain generated by firebase.
I tried to use different sign in options by google provider but doesn’t work.