RBAC

Role-Based Access Control (RBAC) is a security model that restricts system access based on the roles assigned to individual users within an organization. In Nuxtbe, RBAC is implemented as a flexible and powerful authorization system that helps you control what actions users can perform.

RBAC in Nuxtbe

By default, Nuxtbe assignes a role to the user based on the subscription plan paid by the user. To support this feature, Nuxtbe needs 3 tables in the database:

  • roles - to store the roles and the linked products
  • profiles - to store the user's profile
  • profiles_roles - to store the user's role

All of these tables will be created after you run the supabase migration. Read more about migrations.

In order to enable this feature, you have to specify the roles and linked products in the Supabase table roles. For example you have 3 products with their ids from Stripe or LemonSqueezy:

  • Basic - prod_123
  • Pro - prod_456
  • Ultimate - prod_789

And you have 3 respective roles:

  • Basic
  • Pro
  • Ultimate

Then you have to create a new row in the roles table with the following values:

  • role_name - pro
  • product_id - prod_123
-- Insert example roles
INSERT INTO roles (role_name, product_id) VALUES
  ('basic', 'prod_123'),
  ('pro', 'prod_456'),
  ('ultimate', 'prod_789');

Once you've established these product ID to role mappings, the system will automatically assign the appropriate role whenever a user purchases a subscription. Then you're free to check for user's role in the code.