Configurer routeur

Hello Wix community!

I need your help. On our website, when we register, we have 3 proposed registration statuses: client, partner, professional. I would like to know how to do so that when they connect my router (if it is the router the solution) redirects them directly to the page that is reserved for them.

Thanks for your help.

Please write your posts in English.

Hello Wix community!

I need your help. On our website, when we register, we have 3 proposed registration statuses: client, partner, professional. I would like to know how to do so that when they connect my router (if it is the router the solution) redirects them directly to the page that is reserved for them.

Thanks for your help.

@contact51231 Please add more details. Where do you store the statuses? Are you talking about specific page or every page on this website? Do you already have some routers ? When do you want the redirection to take place?

@jonatandor35 The statutes are stored in the section “members of the site” which allows me to give them the necessary authorizations to access the pages dedicated to them.
I don’t have a router.
I would like my router to redirect once the member connects, if he is authenticated as a client he is redirected to the client interface, if he is authenticated as a partner that he is redirected to the partner interface, etc …

Do you store the statues in a databse, do you set roles per user?
Also how exactly to do it depend on the specific flow first.
But basically you can either use routers or use wixLocation.
https://www.wix.com/corvid/reference/wix-router.html (ore complicated)
https://www.wix.com/corvid/reference/wix-location.html#to

No they are not in a database, I can’t do it, I use a personalized registration form, create by six when we create a member section on our site. Yes I define roles by users.

So you want to check the user role and redirect him/her based on this role?

So whenever you want to check it:

import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
let user = wixUsers.currentUser;
$w.onReady(() => {
redirectUser();
wixUsers.onLogin( (u) => {
  user = u;
  redirectUser();
} );
})
function redirectUser(){
user.getRoles()
  .then( (roles) => {
    if(roles.length > 0) {
      if(roles.some(e => e.name === "Clienet")){wixLocation.to("/client-page-path")
    }
})
};
//Or something like this

@jonatandor35 Yes, I think.
Thanks for your help. The code I enter it in "router.js? It tells me an error at the end

@contact51231 No. This code is for the page code panel (if it’s relevant for a specific page) or for the site code panel (if it’s relevant for all pages).

@jonatandor35 How to adapt it only to the login page?

@contact51231 Please describe the flow in details, setp by step.

  1. The user gets to the log-in page, 2. then the user registers? logs in? 3. then the user what?
  1. The user register (choice statut, client, professionnel…) 2. The user connect 3. after connect user redirected on the page specific for client or proffessional…

If you want the user to be redirected from the registration page it’s easy. But if you want the user to be redirected any time he/she logs in, it’s different (and you’ll need to store the role).
Anyway for redirecting from the registration page (page code) →

import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
let status;
$w.onReady(() => {
$w("#checkBoxGroup1").onChange(event => {
status = $w("#checkBoxGroup1").value;
})
wixUsers.onLogin(() => wixLocation.to(`/${status}`));//assuming that the page path and status are the same.
})

I want the user to be redirected every time they log in

This example demonstrates the use of routers for three different types of site visitors: anonymous (free), freemium, premium:

Stripe Payment Processing
Integrate the Stripe Payment processing system into a site. Three levels of user access are demonstrated: visitor, freemium (registered), and premium (paid).

But this solution won’t redirect you onLogin. Right?

@contact51231 ,anyway try to see if the example for the routers fits to your needs.

@jonatandor35 Hmm, not sure it needs to redirect on login. The routers take care of redirection based on the user’s status: free (anonymous visitor), freemium (logged in), premium (logged in and paid up).