I’m getting Firebase: Error (auth/unauthorized-domain) on localhost during google auth. I found that this error is caused when domain is not added to Authorized domains in Firebase. But when i checked Authorized domains there is localhost, and don’t know who is causing this error…
`
const signInWithGoogle = () => {
const provider = new GoogleAuthProvider()
signInWithPopup(getAuth(), provider)
.then((result) => {
console.log(result.user)
router.push("/login")
})
.catch((error) => {
console.log(error)
alert(error.body + ": " + error.message)
})
}
`
2
Answers
As mentioned above, the url to visit is localhost/ not 127.0.0.1 as that is a different domain than localhost/ although it is effectively the same to your machine.
If it is a Vite Project.
Add
1 . import dns from ‘dns’
2 . dns.setDefaultResultOrder(‘verbatim’)
command in vite.config.js
run ”’ npm run dev ”’
it will give you the link to localhost in your terminal to open your app and run it. It will work for sure.
Many thanks for considering my request.