简体   繁体   English

尝试在客户端使用 Firebase 身份验证服务注册用户时出错。 Firebase:错误(auth.network-request-failed)

[英]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.

相关问题 React Native:尝试创建新用户时出现 firebase auth/network-request-failed 错误,但在登录时却没有? - React Native: firebase auth/network-request-failed error when trying to create a new user, but not on login? Firebase 错误:错误(auth.network-request-failed - Firebase error : Error (auth/network-request-failed Firebase Jest auth.network-request-failed'错误 - Firebase Jest auth/network-request-failed' error Firebase 登录时出现“Auth.network-request-failed”错误的项目结果 - Firebase Project Results in "Auth/network-request-failed" error on login [FirebaseError: Firebase: 错误 (auth.network-request-failed) - [FirebaseError: Firebase: Error (auth/network-request-failed) 我在 React 中的 signInWithEmailAndPassword 中出现错误:Firebase: Error (auth/network-request-failed) - I am getting error in signInWithEmailAndPassword in React: Firebase: Error (auth/network-request-failed) Flutter Firebase [firebase_auth.network-request-failed] A.network error (such as timeout, interrupted connection or unreachable host)发生了 - Flutter Firebase [firebase_auth/network-request-failed] A network error (such as timeout, interrupted connection or unreachable host) has occurred 使用 Firebase Auth 进行身份验证时请求短信验证码失败 - SMS verification code request failed when authenticating using Firebase Auth Firebase:错误(授权/用户令牌过期) - Firebase: Error (auth/user-token-expired) 服务器端身份验证令牌验证失败,出现 firebase - server side auth token validation failed with firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM