authentication.login() refreshes to homepage automatically

I have the following code in a custom log in form. When log in is successful, it refreshes and takes me to “/” homepage instead of my desired page. One out of ten times this doesn’t happen and it redirects to the correct page.

export function login_click ( event ) {

**const**  email  =  $w ( '#loginemail' ). value 
**const**  password  =  $w ( '#loginpass' ). value 

authentication . login ( email ,  password ) 
    . then (() => { 
        wixLocation . to ( "/desired-url" ) 
        console . log ( 'Member is logged in' ) 
    }) 
    . **catch** (( error ) => { 
        console . error ( 'Login not approved.' ); 
        console . error ( error ); 
    }); 

}

This post will help you out…
https://www.wix.com/velo/forum/coding-with-velo/persistant-wix-authentication-wix-members-api-issue

Thanks. Are you suggesting a “return” before authentication.login()? I can’t run a currentMember.getmember() after login because by then it would have gone to the homepage already.

The other solution I can think of is to go back to the wix-users API.

The other solution I can think of is to go back to the wix-users API.

Don’t even think about that! You will go into wrong direction!

Did you read all the post carefully? I don’t think so, if you would read it carefully, your logic would tell you what to do and how to proceed.

You can ask me again in 24-hours, if you still have the same issue.
I bet you will be able to solve it by your own, after understanding the post, i provided you.

Try always to think logical → step by step!

Step-1: User logs in → authentication-api used…
Step-2: User is logged in → CurrentMember-Api used…
Step-3: You get your User-Data and so on
Step-4: You say → I can’t run a currentMember.getmember() after login because by then it would have gone to the homepage already .

Here you start to search for solution!

1) setTimeOut() ??? What about this ?
2) onLogin() ??? What about that one ?
3) or just wrong placed wixLocation . to ( “/desired-url” ) ?