HELP - Direct user on Login depending on role

Guys,

I’m struggling big time (totally new to coding, just over a week in but trying).

I have two user / member roles set up “Employer” and “Employee”

I want each to be directed to different profile pages upon login. I’ve tried doing this using the Wix API

How do I code so that it determins where to send each user depening on their role when logging in?

Apologies, just really struggling with this.

Tom

Just use Wix Users API to get the users role and then direct them from that.
https://www.wix.com/corvid/reference/wix-users.html
https://www.wix.com/corvid/reference/wix-users.User.html
https://www.wix.com/corvid/reference/wix-location.html#to

Also, use the forum’s own search button, simply type in user role and look at the searches that come up, there are many that will help you with the code like this one for example.
https://www.wix.com/corvid/forum/community-discussion/user-roles

I’ve already gave a full explanation, but Wix deleted my comments with the spam cleanup.
Tom, if you have more questions, you can ask.

@jonatandor35

My apologies J.D., I would have seen that you had replied if it wasn’t for that annoying spam attack from yesterday.

@givemeawhisky no problem :slight_smile:

@jonatandor35 @givemeawhisky @deleteduser

Guys, I never got notifications on this and for some crazy reason I have no posts showing in my profile anymore?? Saw a load of spam the other day and just gave up.

Anyway - Still struggling on this and can’t understand why.

I’m using the standard wix member login button.

I’ve tried putting the code in both th epage and site panel, neither are working.

I’m putting the following code in to ‘Site’ panel:

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

$w.onReady(function () {

wixUsers.onLogin( (user) => {

let userId = user.id;
 let isLoggedIn = user.loggedIn;
  let userRole = user.role;

if(userRole ===  "Client") {wixLocation.to("/client-dash");}    

if(userRole ===  "Professional") {wixLocation.to("/candidate-dash");} 

  });

});