In this post, I'm going to share an approach I used to design a role-based access control system with TypeScript. The unique aspect of this system is the shared permissions config, which can be utilized both on the backend (for access control) and on the frontend (for UI control). The main idea is to design a robust and type-safe system that ensures users have the correct permissions for their tasks.
Firstly, I define several roles representing different types of users within the system:
export type Role = 'owner' | 'admin' | 'manager' | 'user';