简体   繁体   中英

react-firebase-hook sign in with email and password error massage problem

I want to show error massage when a user want to log in with email and password and do not match. But my error massage show both time when email and password match and not match. This massage duration is like 1s. Anyone help me find wrong code.

const [signInWithEmailAndPassword, user, error] = useSignInWithEmailAndPassword(auth);
    const navigate = useNavigate()
    if (user) {
        navigate(from, { replace: true });
    }

    const handleLogin = async event => {
        event.preventDefault();
        const email = emailRef.current.value;
        const password = passwordRef.current.value;
        await signInWithEmailAndPassword(email, password);
        const { data } = await axios.post('https://powerful-depths-51836.herokuapp.com/login', { email });
        localStorage.setItem('accessToken', data.accessToken);
        // navigate(from, { replace: true });
    }
    let errorMassage;
    if (error) {
        console.log(error)
        errorMassage = <p className='text-red-600 font-bold text-center mt-2'>Please Enter Correct Email and Password</p>
    }

when I console.log(error). all time its value is true;

const [signInWithEmailAndPassword, user, loading, error
] = useSignInWithEmailAndPassword(auth);

Add loading in your code, it will hopefully work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM