尝试使用 firebase 身份验证,但不断出现加载资源失败:服务器响应状态为 400 ()

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

我一直在尝试在我的 firebase wep 应用程序上进行身份验证,但是我遇到了这个问题,任何帮助将不胜感激,请在下面留下我的代码副本。

    # JS
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-app.js";
import { getAuth, createUserWithEmailAndPassword, GoogleAuthProvider, signInWithRedirect,
signInWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-auth.js";
import { getDatabase, set, ref } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-database.js";
omitted the config 
const firebaseConfig = {
    apiKey: "AIzaSyDj5gayMeO7LlMYkLKlMojXuBzLLa46H7I",
    authDomain: "domain is actual domain url ",
    databaseURL: "database url (is the actual url in live code",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "542508426520",
    appId: "1:542508426520:web:fa17e971eb43be4c8e6a6d",
    measurementId: "G-DEMX9X0NYE"
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const provider = new GoogleAuthProvider();
const db = getDatabase(app)
  // inputs


  // register
const register = document.getElementById('register');
function regUser(){
  const email = document.getElementById('email').value;
  const password = document.getElementById('password').value;
  console.log(email, password)
  alert("Account Creation In Progress")
  createUserWithEmailAndPassword(auth, email.value, password.value)
  .then((userCredential) => {
    // Signed up 
    const user = userCredential.user;

    // ...
  })
  .catch((error) => {
    const errorCode = error.code;
    const errorMessage = error.message;
    // ..
  }); 
}
register.addEventListener('click', regUser);
const login = document.getElementById('login');
login.addEventListener("click", function(event){
  
  signInWithEmailAndPassword(auth, email, password)
    .then((userCredential) => {
      // Signed in
      const user = userCredential.user;
      // ...
    })
    .catch((error) => {
      const errorCode = error.code;
      const errorMessage = error.message;
    });
    
  })

我已确保在我的 Firebase 控制台上启用了使用电子邮件和密码登录,这是第一次使用 Firebase,因此仍在学习故障排除的技巧。我在 youtube 上查找过任何教程,但是它们没有帮助,因为每次我尝试时都会遇到相同的错误

javascript firebase firebase-authentication
1个回答
0
投票

你刚刚犯了一个错误,因为你已经呼吁了

document.getElementById('email').value;

signInWithEmailAndPassword(auth, email, password) // <- not email.value and password.value
    .then((userCredential) => {
      // Signed in
      const user = userCredential.user;
      // ...
    })
    .catch((error) => {
      const errorCode = error.code;
      const errorMessage = error.message;
    });
© www.soinside.com 2019 - 2024. All rights reserved.