Acces to "Custom Connexion" by code

Question:
[Clearly ask your question.]

Product:
Wix EDITOR

What are you trying to achieve:

Good evening everyone

I would like to access the WIX “custom login” window via a code.
Normally, to access a page, you access it via “Wixlocation.to()”.
How to open a window by code? (
I tried “Wix Frontend” but without result.

Thanks to all

Here is the code I use:

What have you already tried:

$w(‘#MonCompte’).onClick((event) => {

if (wixUsers.currentUser.loggedIn) {
    wixLocation.to('/moncompte')
}else{
    ???????????? (Go to "Wix connexion")
}    

})

Hey Denis,

wix-users & wix-location are both deprecated APIs. I’d recommend that you switch over to wix-members-frontend & wix-location-frontend respectivley.

Your page code should look something like this:

import { authentication } from "wix-members-frontend";
import wixLocationFrontend from 'wix-location-frontend';

$w.onReady(function () {

    const isLoggedIn = authentication.loggedIn();

    $w('#MonCompte').onClick((event) => {
        if (isLoggedIn) {
            wixLocationFrontend.to('/moncompte');
        } else {

            let options = {
                mode: 'login', //either 'login' or 'signup'
                modal: true //true for popup, false for fullscreen
            }

            authentication
                .promptLogin(options)
                .then(() => {
                    console.log("Member is logged in");
                })
                .catch((error) => {
                    console.error(error);
                });
        }
    })

});
1 Like

Hi Pratham,

Thank you for this quick and efficient feedback. Everything is OK and works perfectly. I also took the opportunity to update my various codes concerning the deprecated wix-users & wix-location APIs, and updated them to wix-members-frontend & wix-location-frontend as you asked me to do. Thanks a lot …

Have a nice weekend

1 Like