1

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... Firebase screenshot

`

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)
        })
}

`

3
  • Do you have Google Authentication activated in your console? Are you perhaps visiting the site at 127.0.0.1 rather than localhost/ ? Commented Nov 9, 2022 at 17:20
  • Ahhh, you were right, vite using 127.0.0.1 instead of localhost... TY! Commented Nov 9, 2022 at 17:37
  • I'm going to add the answer real quick below. Thanks for the verification. Commented Nov 9, 2022 at 18:02

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.