New 🎉 Next.js 13 & Subscriptions. Learn more →
Documentation

Permissions

Based on the customers subscriptions users can access different features or have different limitations in the app.

We have added an example of how to check for permissions in the example app by only allowing the creation of one client on the dashboard when the user is not subscribed to any plan.

Check for permissions

To check for permissions you can use the useUserPermissions hook. This hook by default only returns the boolean if you the user is subscribed to any plan and if the permissions are loading.

const { isUserSubscribed, loading } = useUserPermissions();

If you want to check for specific permissions based on the subscriptions you can adjust the hook to return the permissions in the lib/permission.ts file. For example if you want to allow a certain feature only for users with the Pro plan and up you could do the following:

export function useUserPermissions() {
  const { currentlySubscribedPlan, loading } = useUserSubscriptions();

  const subscribedPlanId = currentlySubscribedPlan?.id;

  const canUserDoSomething = useMemo(
    () => subscribedPlanId && [SubscriptionPlanId.Pro, SubscriptionPlanId.Ultimate].includes(subscribedPlanId),
    [subscribedPlanId]
  );

  return {
    loading,
    isUserSubscribed: !!currentlySubscribedPlan,
    canUserDoSomething,
  };
}

We will add a more advanced permission system in the future and examples on how to implement server-side permissions with RLS in your supabase database. So stay tuned!

supastarter

Get your SaaS started in minutes

Save time and focus on your business with supastarter, the scalable and production-ready boilerplate for your SaaS.

Get started →
supastartersupastarter

© 2022 supastarter. All rights reserved.

Product

  • Demo
  • Pricing
  • FAQ
  • Documentation
  • Changelog
  • Roadmap
  • Starter templates