The most common authorisation scenario you will find yourself building is controlling access to features based on the account’s billing plan.
Users without a plan
By default, users who have not signed up for a plan will only have access to authentication and account profile pages. This ensures that users without an active plan cannot access features beyond the basics.
On the client side, users are restricted to just authentication and profile management until they choose a plan.
On the server side, actions such as inviting child users, accessing AI endpoints, or creating API keys should be disabled for users without an active plan. For example:
// check account has a plan
const accountData = await account.get({ id: req.account });
utility.assert(accountData.plan, res.__('account.plan_required'));
As you build custom endpoints for your own features, it’s important to include this check to ensure actions cannot be performed without an active plan via the API.
Restricting features by plan
For custom features, add an entitlement to each relevant plan in stripe.plans, then check the current account’s configured plan before performing the action. For example, after adding a boolean store_files field to the plans:
const accountData = await account.get({ id: req.account });
const plans = config.get('stripe.plans');
const currentPlan = plans.find(plan => plan.id === accountData.plan);
utility.assert(currentPlan?.store_files, res.__('file.save.not_permitted_on_plan'));
Add the corresponding message to your locale files. Decide separately whether the feature needs an active paid subscription or should also be available to free accounts.