skip to Main Content
try{
     const user = await createUserWithEmailAndPassword(auth, email, password)
     console.log(user);
     navigate('/login');
     toast.success('Registered Successfully');
                
    }
    catch(error){
       console.log(error);
    
    } 

I’m trying to display toast message after navigates to login page. But I didn’t getting any toast notification after redirecting to login page. Plase help me to slove this

2

Answers


  1. I guess you need to add some sort of delay before navigating to other screen otherwise the process would be so fast that user won’t be able to see the toast. Try doing like this:

    try {
         const user = await createUserWithEmailAndPassword(auth, email, password)
         console.log(user);
         toast.success('Registered Successfully');
         
         setTimeout(() => {
           navigate('/login');
         }, 1000);                    
      }
      catch(error){
           console.log(error);      
      } 
    
    Login or Signup to reply.
  2. your code doesn’t reach toast.success because your app navigates to /login.

    you need to fire toast from login page after passing a query param.

    navigate('/login?success=true');
    

    in login page:

    const query = new URLSearchParams(window.location.search);
    const myParam = query.get("success");
    
    if(myParam === 'true'){
       toast.success('Registered Successfully');
    } 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search