Custom login screen logic

I have defined the login screen to be custom, so I was able to add some specific actions.
WIth the original submit button, I want do add a process if login is successfull ( a process that retrieves user specific data).
To achieve that, I put some code in the button click event, and check if login has been successful (with isLoggedIn = authentication.loggedIn();).
UNfortunately, this seems always false.

So my questions are

  • in which order is the code executed between the hidden code that do the login process, and my visible code?
  • IS that another way to do this check?

Claude

It is possible that your authentication.loggedIn() method is being called before the login process is completed.

Instead, I recommend using the authentication.onLogin() event handler which runs when a member logs into your site.

1 Like

Seems promising, but where should I put this code ? In the submit button or elsewhere?

You did not read the API, which was provided by THOMAS !!!


import {authentication} from 'wix-members-frontend';

$w.onReady(()=>{
    $w('#button1').onClick((e)=>{console.log(e.target.id);});
    $w('#button2').onClick((e)=>{console.log(e.target.id);});
    $w('#button3').onClick((e)=>{console.log(e.target.id);});

    authentication.onLogin(async (member) => {
      const loggedInMember = await member.getMember();
      const memberId = loggedInMember._id;
      console.log(`Member ${memberId} logged in:`, loggedInMember);
    });
});