[英]Error when trying to register a user using Firebase Auth service on the client side. Firebase: Error (auth/network-request-failed)
I am trying to do authentication and registration by email and password using the internal authentication system within Firebase and Vue3 on the client.我正在尝试通过 email 和密码在客户端上使用 Firebase 和 Vue3 中的内部身份验证系统进行身份验证和注册。 I get the following error when I trying to register a user:
尝试注册用户时出现以下错误:
Firebase: Error (auth.network-request-failed).
Firebase:错误(auth.network-request-failed)。
POST http://localhost:9099/identitytoolkit.googleapis.com/v1/accounts:signUp?key=AndHereIsTheKeyFromFB.net::ERR_CONNECTION_REFUSED发布 http://localhost:9099/identitytoolkit.googleapis.com/v1/accounts:signUp?key=AndHereIsTheKeyFromFB.net::ERR_CONNECTION_REFUSED
Component with registration form:带有注册表单的组件:
<template>
<p><input type="text" placeholder="Email" v-model="email" /></p>
<p><input type="password" placeholder="Password" v-model="password" /></p>
<p><button @click="register">Submit</button></p>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import {getAuth, createUserWithEmailAndPassword} from "firebase/auth";
const auth = getAuth();
const email = ref('')
const password = ref('')
const router = useRouter()
const register = () => {
createUserWithEmailAndPassword(auth, email.value, password.value)
.then((data) => {
console.log('Successfully logged in!');
})
.catch(error => {
console.log(error.code)
alert(error.message);
});
}
</script>
main.js with firebase configurations:具有 firebase 配置的 main.js:
const firebaseConfig = {
apiKey: "key",
authDomain: "authDomain",
databaseURL: "dbUrl",
projectId: "Id",
storageBucket: "sB",
messagingSenderId: "msgSenderId",
appId: "Id"
};
initializeApp(firebaseConfig)
if (location.hostname === "localhost") {
connectAuthEmulator(getAuth(), "http://localhost:9099");
}
I also tried to change the hostname from localhost to 127.0.0.1, but this did not affect the result in any way.我还尝试将主机名从 localhost 更改为 127.0.0.1,但这对结果没有任何影响。 My experience with Firebrace and authentication through it is small, so I will be glad of any help in this situation
我对 Firebrace 和通过它进行身份验证的经验很少,所以我很乐意在这种情况下提供任何帮助
Fixed the issue with some changes to main.js configuration file contains the following lines from this:修复了对 main.js 配置文件的一些更改的问题,该文件包含以下几行:
if (location.hostname === "localhost") {
connectAuthEmulator(getAuth(), "http://localhost:9099");
}
to this:对此:
if (location.hostname === "localhost:8080") {
connectAuthEmulator(getAuth(), "http://127.0.0.1:9099");
}
I don't know why, but the changing of port and localhost to IP like indication worked for me:)我不知道为什么,但是将端口和本地主机更改为 IP 就像指示对我有用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.