Hello I have a login page that has 2 conditions:
1- if user is logged in: Show/Hide elements + Redirect to —> Page
2- if user is not logged in: Email/Password Fields: Login button —> Page
Ive been trying to add another line to perform these functions based on roles
e.g: if Role A “Staff” —> Redirect to Page A
if Role B “Client” ----> Redirect to Page B
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
$w.onReady(function () {
if (wixUsers.currentUser.loggedIn) {
$w("#loginNow").label = "Logging in";
$w("#loginUsername").hide();
$w("#loginPassword").hide();
// Redirect the user to the dashboard
wixLocation.to('/account/Dashboard/');
}
})
export function loginNow_click(event) {
let email = $w('#loginUsername').value;
let password = $w('#loginPassword').value;
wixUsers.login(email,password)
.then(()=>{
wixLocation.to('/account/Dashboard/');
})
.catch( (err) => {
console.log(err);
$w("#errorMessage").show();
});
}
Thanks.
Vacation + I’m working right now on a big project that can’t be done with Velo (lots of drag&drops + canvas drawing) so my mind is somewhere else
@j.d. thanks for the code; however, when I am using this any visitor is forced to my login page and can’t explore any of the website that is non-member. Any thoughts on troubleshooting this?