I know how to restrict pages using the members and paid members in the UI. However I really need to do it in code. I want to restrict the event registration page and I cannot find an example anywhere to do be able to do this in code since this isn’t a page I can set restrictions on in the ui.
This is all I have so far. I can grab the user info but I don’t know how to use that to restrict the page and let them be directed to the “only paid subscribers” that directs them to the plans to purchase page.
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
//TODO: write your page related code here...
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then( (email) => {
let userEmail = email; // "user@something.com"
} );
user.getRoles()
.then( (roles) => {
let firstRole = roles[0];
let roleName = firstRole.name; // "Role Name"
let roleDescription = firstRole.description; // "Role Description"
} );
user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name; // "Gold"
let startDate = firstPlan.startDate; // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
let expiryDate = firstPlan.expiryDate; // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
} );
});
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
//TODO: write your page related code here...
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then( (email) => {
let userEmail = email; // "user@something.com"
} );
user.getRoles()
.then( (roles) => {
let firstRole = roles[0];
let roleName = firstRole.name; // "Role Name"
let roleDescription = firstRole.description; // "Role Description"
} );
user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name; // "Gold"
let startDate = firstPlan.startDate; // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
let expiryDate = firstPlan.expiryDate; // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
} );
});