Wix-Location, Wix-Users API login

I want,when the user is logged in this button to be enabled, and when the user clicks on it to redirect them to /clients-list/$(UserID) or /clients-list/$(email) [email would be more prefferable].
But when the user is logged out the button to be .hidden
What so ever, once im logged in the button remains disabled…

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';

$w.onReady(() => {
  if (!wixUsers.currentUser.LoggedIn)
    $w('#PersonalPage').disable();
});

export function personalPage_onClick() {
  let userId = wixUsers.currentUser.id;
  wixLocation.to(`/client-data/${userId}`);
}

Hi Maria,

How are you having users login to the site? Have you tried using the promptLogin function with a button and using .then of the returned promise enable the button?

Something like this in addition to the rest of your code, where the login button is called customLoginButton:

import wixUsers from 'wix-users';

export function customLoginButton_onClick(event) {   
  wixUsers.promptLogin()  
    .then( (user) => {  
      $w('#PersonalPage').enable(); 
    } ); 
}
1 Like

Hello Sam and thank you so much for your answer!
The button now is enabled, once the user has logged in!
But, it doesnt redirect them to the page…it does nothing.I cick on it and it does nothing

Is it possible to check it out by making you a mod at the site?

Hi Maria -
do you know how to use the browser’s console?
in case of errors it may show some messages on what exactly went wrong.
try to open it by using cmd+alt+J (on macs, and for chrome browser). see if there are messages there after the click event is triggered.