Hi everyone,
I’m currently facing a challenge with my Wix website and could use some help. I’m trying to set up redirections so that users are taken to specific pages based on their subscription plans when they log in. Here’s a breakdown of what I’m aiming to achieve:
Vervente Plan: Redirect users to the Vervente page.
Maestino Plan: Redirect users to the Maestino page.
Annual Plan: Redirect users to the Maestrino page.
I’ve tried a few different approaches using Wix Velo (formerly Corvid), but I’m having trouble getting the code to work as expected. Here’s a snippet of what I’ve been working with:
javascript:
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
wixUsers.currentUser.getRoles()
.then((roles) => {
let userRole = roles[0].name; // Assuming users have only one role
switch (userRole) {
case 'Vervente':
wixLocation.to('/vervente-page');
break;
case 'Maestrino':
wixLocation.to('/maestrino-page');
break;
case 'Annual':
wixLocation.to('/maestrino-page');
break;
default:
console.log('Role not found');
break;
}
})
.catch((error) => {
console.error('Error fetching roles:', error);
});
});
Issues I’m Facing:
The redirection doesn’t always work as expected. Sometimes, users aren’t redirected to the correct page, and it’s always has an error when testing like the API?
There seems to be a delay or failure in fetching the user roles, causing the redirection to fail.
I’m unsure if I’m correctly handling users with multiple roles.
Has anyone else encountered this issue or can anyone point out what might be going wrong? Any advice or code examples would be greatly appreciated. Thank you!