member login redirect

Hi ,

I have two roles setup in member management ( i.e. Role A and Role B)
I have setup two member only hidden page , one for Role A only and other page for Role B only

How can i direct Role A and Role B members to their own page after login?

Moreover, is there any function that hidden page will only show after permitted member login?

Thanks very much

Hi Michael!

If you want to direct users to their pages according to the role - you’ll first need to get the role of the current user . It would look something like that:

wixUsers.currentUser.getRoles()
        .then((roles) => {
              let currentRole = roles[0];
              if(currentRole === "Role A"){
              //direct the user to the Role A page.
              } else if(currentRole === "Role B") { 
                        //direct the user to the Role B page.
                      }

About the hidden page question, it is not possible to effect/change the visibility status of a page via code.
What you can do is to set the page to ‘hidden’ and once you recognize that the user holds one of the roles (you can add this to the code above) simply show( ) a button that navigates to the relevant page

Doron.

Thanks Doron,

I am sorry, i am new to this :stuck_out_tongue:

Role A = L1
Role B = L2

I added the code to the site but it does not work

});wixUsers.currentUser.getRoles()
.then((roles) => {
let currentRole = roles[0];
if (currentRole === “L1”){
//7183595476.wixsite.com/hysengroupinc/vendor-l1
} else if (currentRole === “L2”) {
//7183595476.wixsite.com/hysengroupinc/vendor-l2

Instead

I am thinking to create a welcome page with 2 button which show if assigned role login

#Button1 - linked to a hidden page
#Buttone2 linked to a hidden page

If Role L1 login , then #button 1 shows and #button 2 hides
If Role L2 Login, then #button 2 shows and #button 1 hides

What will be the code for it?

Thanks very much Doron

Mike


Could you please share a link to your site/editor?
It is somewhat not clear.

Doron.

https://7183595476.wixsite.com/hysengroupinc

Thanks

Main goal is let Role A sees Role A only page and Role B sees his own

The code I shared before is a snippet that requires adjustments to your site.
You obviously need to add all the imports of the API’s that are included in it, such as -
wixUsers
wixLocation

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

$w.onReady(function () {                                            
   wixUsers.currentUser.getRoles()
           .then((roles) => {
                let currentRole = roles[0];
                if(currentRole === "Role A"){
                   $w('#button1').show()
                   $w('#button2').hide()
                  } else if(currentRole === "Role B") { 
                         $w('#button2').show()
                         $w('#button1').hide()
                      }
             })
 });

You can do it like this (by connecting the buttons directly to the pages you want) or you can use a single button and run this code every time it is clicked and according to the result you’d get - send the user to the relevant page.

Doron.

Hi Doron,

i am so appreciate and thanks for your help.

Too bad, i copy and paste your code into the the vendor page code but button 1 and 2 still both show no matter which role login.

hi doron, i try to add this code to my site. where should i put it? on login page?

Hi Michael Yung - I am looking to do exactly the same. Did you manage to make it work? Thank you!

Hi Jakob , Sorry to tell you that still not working. Hope you can figure it out and share the solution with me. Thanks