Is it possible to redirect a site member to a specific page using their role?

I have two custom member role: Freelancer and Client. I would like to automatically redirect
a member to page 1 if he/she is a freelancer or page 2 if he/she is a client. Is it doable with if…else… of some sort or perhaps a dropdown (though not ideal)? Thanks!

Nevermind. I somehow got it working./ Not sure if the code is the best but it worked.

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import wixData from 'wix-data';

$w.onReady(function () {
$w("#forgotPassword").onClick((event) => {
//wixWindow.lightbox.close()
wixUsers.promptForgotPassword()
.then(() => {
//
})
.catch((err) => {
let errorMsg = err;
});
});
});
export function loginButton_click(event) {
let email = $w("#email").value;
let password = $w("#password").value;
wixUsers.login(email, password)
.then(() => {
console.log("User is logged in");
})

.catch((err) => {
console.log(err);
$w("#errorMessage").expand(); //Use a regular text element set to 'collapse on load' from the Properties Panel.
});
}

$w.onReady(function () {
wixUsers.onLogin((user) => {
user.getRoles()
.then((roles) => {
let firstRole = roles[0];
let roleName = firstRole.name;
if (roleName === "Client") {
console.log("Client User is logged in");
wixLocation.to("/dashboard");
} else {
wixLocation.to("/contact");
console.log("Freelancer user is logged in");
//I used the contact page as a test only together with a console log.
}
});
});
})

Well done for getting it working yourself even if it isn’t the best as you say, although you only need the one onReady function for your page, you don’t need the second one in your code.

Thank you! I’ll redo it. :grinning: