Firebase 身份验证不适用于 127.0.0.1,但适用于 localhost

问题描述 投票:0回答:1

我在项目中使用 Firebase 身份验证,并且遇到了一个问题:使用

127.0.0.1
作为主机时身份验证不起作用,但使用
localhost
则可以正常工作。你也是这样吗?任何见解或建议将不胜感激。

<!DOCTYPE html>
<html>

<body>
    <button id="btn1">Log in/Sign up</button>
    <button id="btn2" disabled>Sign Out</button>

    <script type="module">

        import { initializeApp } from "https://www.gstatic.com/firebasejs/10.9.0/firebase-app.js"
        import { getAuth, GoogleAuthProvider, signInWithPopup, signOut} from "https://www.gstatic.com/firebasejs/10.9.0/firebase-auth.js"
        const firebaseConfig = {
            // my config
        }

        const app = initializeApp(firebaseConfig)
        const auth = getAuth()
        const provider = new GoogleAuthProvider()

        async function SignIn() {
            await signInWithPopup(auth, provider)

            btn1.disabled = true
            btn2.disabled = false
        }

        async function SignOut() {
            await signOut(auth)

            btn1.disabled = false
            btn2.disabled = true
        }

        btn1.addEventListener('click', SignIn)
        btn2.addEventListener('click', SignOut)

    </script>
</body>

</html>
javascript firebase firebase-authentication localhost
1个回答
0
投票

您需要将

127.0.0.1
添加到 Firebase 控制台中的 授权域 列表中。

© www.soinside.com 2019 - 2024. All rights reserved.