Issue with Redirect to and history.push()

Hi,

I’m am unable to redirect users upon them signing in. I have also tried history.push. Could someone please tell me what I’m doing wrong?

Thanks in advance. :grinning:

        const redirect = (error: any) => {
           
            if(!error){
                
                return <Redirect to="/dashboard" />
                
            } else if (error.error == 403){
                setError('Invalid User Name or Password')
                throw new Meteor.Error('Invalid User Name or Password', 'Invalid User Name or Password');
            } else {
                throw new Meteor.Error(error, error)
            }  

        }

        const selector = values.email;
        const password = values.password;
        Meteor.loginWithPassword(selector, password, function(error: any){
            redirect(error)
        });

If dashboard has a check if the user is already logged in, your callback might be firing first before the user account in the client is updated as logged in

So the redirect might be happening but it is redirected back because the user is not logged in yet at the moment of checking

1 Like

@rjdavid I just want to say a hugeeee thank you. You’ve put me on the right track. The user account isn’t updating before the call back like you said. How would you solve it?

Check about Meteor.loggingIn()

2 Likes