Feeling a bit stuck after reading a ton of articles and following a bunch of other Stack answers (none of which have worked, most of which don’t relate to my exact problem).
I’ll describe the problem and behavior first, then talk through what I’ve tried so far, and then show the code.
Problem
Doing development locally using Vue/Vite with Firebase tools installed including the emulators and am adding Google signin. The behavior seems to be that both signInWithRedirect and signInWithPopup really want to use https for their URLs and nothing I can do has convinced them to do otherwise. This results in errors for both telling me that they cannot establish a secure connection (either in the redirect, because it tries to redirect to https://localhost:5173/, or it wants to popup an iframe and assign the iframe uri to https://localhost:5173). The host and port match what my project is running on, of course.
What I have tried
Oh, a lot of things. I may be forgetting some, but the most obvious ones include:
- Ensuring that my Google OAuth project has whitelisted http://localhost:5173 as both a source and redirect URI
- Ensuring that Firebase is connected to that Google Oauth project
- Ensuring that my .env.local has an entry for the auth_domain to be overridden and that it’s successfully being overridden (though, note if I try and add the protocol it strips out the : so that it becomes https://http//localhost:5173/…)
- Trying to pass the Auth emulator URL as a string to the
signInWith<X>() function as described in one of the Firebase docs I found, this resulted in a firebase auth argument error, and looking at the actual API documentation, it doesn’t appear supported (or if it is, it’s not documented there).
- Clearing the browser cache did nothing to affect any of this behavior (not sure why it would, given what’s happening, but it was one of the Stack recommendations that I found).
Code
The code I’ve tried both ways, but here you go:
const auth = getAuth(app);
const provider = new GoogleAuthProvider();
console.log(import.meta.env.VITE_FIREBASE_AUTH_DOMAIN)
// signInWithRedirect(auth, provider)
// .then((result) => {
// console.log(result)
// }).catch((err) => {
// console.log(err.message)
// });
signInWithPopup(auth, provider)
.then((result) => {
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const user = result.user;
console.log(JSON.stringify(user));
}).catch((error) => {
console.error(error.message);
})
Is there a way to get the GoogleAuthProvider to recognize that I’m working on Localhost and therefore will never be able to work with HTTP?
Thanks!