How I can wait until my async await function gives something and use that peace of state

Viewed 21

I am actually authenticating a firebase connection and want to route to the home page after authentication.

The problem is that whenever I clicked the button it has a wait of 1s almost to receive the resolved state from firebase, and I know that async await resolve after set time out in call stack. So what is the method that should execute it I get resolve state?

This is my approach:

const isActiveStatus =useCallback(() => {
    currentUser !== null ? setIsActive(true) : setIsActive(true) 
    console.log("is Active: "+ isActive)
    isActive ? navigate("/") : console.log("user is not Active")
}, [currentUser])

async function handleSubmit(event) {
    event.preventDefault();
    
    try {
        setError("")
        setLoading(true)
        await signin(emailRef.current.value, passwordRef.current.value)
        isActiveStatus()
        console.log(isActive)
    } catch {
        setError("There is some issue in logging in")
    }
    setLoading(false)
}
0 Answers
Related