Firebase Error: Auth/Internal Error showing while Signing in

Viewed 189

I have initiated this project for a while now, and I remember that when I started, the login section of the email and password authentication was working fine, but at a point, it never did work fine anymore. I started getting this "Firebase Error: Auth/Internal Error" on my console.

If you ask me, I have no idea as to why that's happening.

import { onAuthStateChanged } from "firebase/auth";
const [userData, setUserData] = useState(null);
const userHandler = (user) => (user ? setUser(user) : setUser(null));

  useEffect(() => {
    onAuthStateChanged(auth, (user) => userHandler(user));
  }, []);

That is how I'm changing my state once the authState changes.

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
import { getStorage } from "firebase/storage";

const firebaseConfig = {
  apiKey: "xxxxx-xx",
  authDomain: "my-app.firebaseapp.com",
  projectId: "my-app",
  storageBucket: "my-app.appspot.com",
  messagingSenderId: "xxxx-xxx",
  appId: "xxxx-xx",
  measurementId: "xxxx-xx",
};

const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const storage = getStorage(app);

export default getFirestore();

And here's how my firebase cofiguration looks.

import {
  signInWithEmailAndPassword,
  RecaptchaVerifier,
  signInWithPhoneNumber,
} from "firebase/auth";
import { auth } from "../store/server.config";
import db from "../store/server.config";
import { onSnapshot, doc } from "firebase/firestore";
const signInUser = () => {
    setLoading(true);
    setErrors(null);

    if (email === "" || emailPassword === "") {
      setErrors("Please fill the needed fields.");
      setLoading(false);
    } else {
      signInWithEmailAndPassword(auth, email, password)
        .then(async (userCredentials) => {
          console.log(userCredentials.user);
          try {
            onSnapshot(doc(db, "users", email), (snapshot) => {
              setUserData(snapshot.data());
              localStorage.setItem("FirstName", snapshot.data().firstname);
              localStorage.setItem("Email", email);
              setLoading(false);
              navigate("/");
            });
          } catch (err) {
            console.error(err);
          }
        })
        .catch((err) => {
          setLoading(false);
          console.error("Error message>>>", err.message);
          if (err.message === "Firebase: Error (auth/wrong-password).") {
            setErrors("Wrong Password.");
          } else if (
            err.message ===
            "Firebase: Access to this account has been temporarily disabled due to many failed login attempts. You can immediately restore it by resetting your password or you can try again later. (auth/too-many-requests)."
          ) {
            setErrors(
              "Account temporarily disabled. Please contact customer support."
            );
          } else if (err.message === "Firebase: Error (auth/user-not-found).") {
            setErrors("This account does not exist in our database.");
          }
        });
    }
  };

And finally, here's how I'm signing a user in with Email and password. I don't know if the details provided are useful. Please someone help out.

0 Answers
Related