<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ndomaprecious on Medium]]></title>
        <description><![CDATA[Stories by Ndomaprecious on Medium]]></description>
        <link>https://medium.com/@ndomaprecious95?source=rss-04e28bde36b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lRfEZfIXTS4bVkjU</url>
            <title>Stories by Ndomaprecious on Medium</title>
            <link>https://medium.com/@ndomaprecious95?source=rss-04e28bde36b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 05:49:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ndomaprecious95/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Secure RBAC and ReBAC Based Real-Time Collaborative Text Editor with Nest.js]]></title>
            <link>https://medium.com/@ndomaprecious95/secure-rbac-and-rebac-based-real-time-collaborative-text-editor-with-nest-js-1eeb40b0a52c?source=rss-04e28bde36b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1eeb40b0a52c</guid>
            <category><![CDATA[realtime-applications]]></category>
            <category><![CDATA[rebac]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[rbac]]></category>
            <dc:creator><![CDATA[Ndomaprecious]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 21:10:01 GMT</pubDate>
            <atom:updated>2025-02-05T21:10:01.039Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1BtNmF7WDt4RkF6zkNBALA.png" /></figure><h3>Secure RBAC and ReBAC Based Real-Time Collaborative Text Editor with Nest.js and Gatsby Using <a href="http://permit.io/">Permit.io</a></h3><p><a href="https://www.permit.io/blog/what-is-rbac">Role-based access Control (RBAC)</a> and <a href="https://www.permit.io/blog/what-is-rebac">Relationship-Based Access Control</a> are one of the fundamental aspects of modern application security. It allows administrators to control users’ permissions according to predefined roles. RBAC provides a secure way for users such as Admins, Editors, and Viewers to interact with the resources in collaborative applications, especially real-time, multi-tenant systems. However, it is not easy to implement dynamic, scalable RBAC and collaborate in real-time while ensuring security, for example, synchronizing permissions across users to enforce security and permission policies without disrupting the seamless interaction of the application.</p><p>In many of these environments, traditional authorization systems can not keep up with changing permission structures or the time-sensitive needs of real-time applications. Nest.js and Gatsby provide a solid full-stack basis to build performant and real-time applications; however, implementing a secure, dynamic RBAC requires a more specialized approach.</p><p>In this tutorial, you’ll learn how to:</p><ul><li>Build a real-time collaborative text editor with synchronized updates between users with enforced role-based permissions (Only allow “Editors” to edit or only allow “Viewers” to access).</li><li>Implement dynamic RBAC using <a href="http://permit.io/">Permit.io</a>, a universal authorization service, to manage roles and permissions for multi-tenant organizations without hardcoding logic.</li><li>Secure server-side APIs with Nest.js by validating user permissions in real-time, ensuring actions like creating, editing, or deleting content align with their roles.</li></ul><p>By the end, you’ll build a secure, real-time text editor where permissions adapt dynamically to user roles and organizational needs. This tutorial will equip you with patterns for scaling authorization in any collaborative application, balancing security with responsiveness to users’ needs.</p><p>Let’s dive in!</p><h3>Prerequisites</h3><p>To follow along with this, ensure you’ve met the following requirements.</p><ol><li>Have a <a href="http://permit.io/">Permit.io</a> account</li><li>Have <a href="https://www.docker.com/">docker</a> installed on a local machine</li><li>Have an <a href="https://appwrite.io/">Appwrite</a> account for Authentication and data storage.</li><li>Have a <a href="https://liveblocks.io/">Liveblocks</a> account to integrate collaborative features.</li><li>Have <a href="https://nodejs.org/en/download">Nodejs runtime</a>, <a href="https://www.gatsbyjs.com/docs/quick-start/">Gatsby</a> and <a href="https://docs.nestjs.com/">NestJS</a> CLI installed.</li></ol><h3>Setting Up The Real-time Collaborative Text Editor</h3><p>The get starter, head to your terminal and clone the started project with the following commands:</p><pre>git clone https://github.com/preshenv/collab_text_editor<br>cd collab_text_editor</pre><p>Next, install the project dependencies and start your development server:</p><pre>npm install<br>gatsby develop</pre><p>You will run into some errors at this stage as your project lacks some supportive technologies used in its development. Thus, you’d need to have these environment variables available:</p><pre>PUBLIC_LIVE_BLOCKS_SECRET_KEY=&#39;LiveBlocks secret key&#39;<br>PUBLIC_APPWRITE_ENDPOINT=&#39;Appwrite endpoint&#39;<br>PUBLIC_APPWRITE_PROJECT_ID=&#39;Appwrite project id&#39;<br>APPWRITE_DATABASE_ID=&#39;Appwrite database id&#39;<br>APPWRITE_DOCUMENT_COLLECTION_ID=&#39;Appwrite document collection id&#39;<br>APPWRITE_FOLDER_COLLECTION_ID=&#39;Appwrite folder collection id&#39;</pre><blockquote><em>Note: you can check out </em><a href="https://www.gatsbyjs.com/docs/how-to/local-development/environment-variables/"><em>how to create a .env</em></a><em> file on the Gatsby website.</em></blockquote><p>In the next section, we will show how to get these variables one after the other.</p><h3>Setting Up <a href="https://liveblocks.io/">Liveblocks</a></h3><p>Liveblocks lets you add real-time features to your product through its APIs. That is very useful in helping us achieve a collaborative feature in our app. So to get the PUBLIC_LIVE_BLOCKS_SECRET_KEY, we&#39;ll create a new development project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Eq--ZrQm9mBEwbO5.png" /></figure><p>After that, go to the <strong>API key</strong> section and copy both the public and secret keys. Then, paste the secret key into the .env.development file in the corresponding variable above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pyU-i8Q6n5qJ2tpk.png" /></figure><p>And that’s it; now we can proceed to set up Appwrite.</p><h3>Setting Up <a href="https://cloud.appwrite.io/">Appwrite</a></h3><p><a href="https://cloud.appwrite.io/">Appwrite</a> is a backend service that provides features like authentication, database, and storage, making sure you have a smooth product development. For this tutorial, we used two of Appwrite’s features: authentication and database. These features require us to provide sensitive variables to connect our app with Appwrite.</p><ol><li>Create a project called <strong><em>Collaborative Editor</em></strong> in the <a href="https://cloud.appwrite.io/console/">Appwrite console</a>. You can give it a personalized ID, or one will be generated for you.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xCViBoCP4cStrN_X.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Om0yXZmoZCqHrY8F.png" /></figure><p>2. Navigate to <strong>Overview → Settings</strong> and copy the <strong><em>Project ID</em></strong> and <strong><em>API endpoint</em></strong> to your Gatsby .env.development file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3A43m3dR-FYShODT.png" /></figure><p>3. Afterwards, return to the <strong>Overview</strong> section and add a web platform. When creating this platform, name it <strong><em>gatsby collab editor</em></strong> and set the hostname <strong><em>localhost</em></strong> since we are using a local environment now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9NhKy4zuj0dlaSBP.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A2Jt1e4Jre0YG3A3.png" /></figure><p>You might need to configure Appwrite’s authentication differently, but it is enough now. Now, you’ll need to set up the database and collections.</p><blockquote><em>Note: IDs are auto-generated if you do not set a personalized ID.</em></blockquote><ol><li>Go to the <strong>Databases</strong> section and create new database called <strong><em>collab_docs_db</em></strong>. After, copy the <strong><em>Database ID</em></strong> by clicking on the ID and paste it into your Gatsby .env.development file.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9ToC4wk1fEp9lvFx.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IUctjNDQ-DdB0M3g.png" /></figure><p>2. Next, populate the database with two collections called <strong><em>document</em></strong> and <strong><em>folder</em></strong>. Then, copy their IDs to your Gatsby .env.development file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hoRAqBe9LGo8uuTX.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*63k276HJ7o7keDTl.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*corwmlL3Rqma19UK.png" /></figure><p>For the <strong><em>document collection</em></strong>, add the four attributes below by going to the <strong>Attributes</strong> section within the collection:</p><ul><li>roomId (string, 36, required)</li><li>storageData (string, 1073741824)</li><li>title (string, 128)</li><li>created_by (string[], 20)</li></ul><blockquote><em>Note: you can create string[] by creating a normal string but toggling the Array option during its set up.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oxwZZniwGrlr7dgZ.png" /></figure><p>Navigate to the <strong>Settings</strong> tab within the collection and scroll to the <strong>Permissions</strong> section. Next, click <strong><em>Add role</em></strong> and select <strong><em>All users</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Isc8h0sobhLxQSGf.png" /></figure><p>5.1.2. Then, check all the CRUD permission boxes and toggle on <strong>Document security</strong> in the <strong>Document security</strong> section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NmDvEArMYkt51KOu.png" /></figure><p>For the <strong><em>folder collection</em></strong>, add three attributes:</p><ul><li>title (string, 128)</li><li>created_by (string[], 20)</li><li>document (relationship with document collection)</li></ul><p>To replicate the third attribute, create a relationship attribute with a two-way relationship between folder and document collection. Then, set <strong><em>one-many</em></strong> as the relation between the collections. That means <strong><em>folder collection</em></strong> can contain many <strong><em>document collection</em></strong> but <strong><em>document collection</em></strong> can belong to one <strong><em>folder collecttion</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qbbGUiVqj1fP86Y3.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zAMRRBQb6iw687rW.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9Or4rqmSjFSoLGAX.png" /></figure><p>We also set the permissions and document-level security as we did earlier in the document collection.</p><p>Once you’ve dealt with that side of things, run gatsby develop once more to build your project.</p><h3>Configuring <a href="http://permit.io/">Permit.io</a> for RBAC and ReBAC</h3><p>Before we can start writing code, we will need to set up our RBAC and ReBAC access controls. We will create custom roles instead of the generic roles created by <a href="http://permit.io/">Permit.io</a> in the dashboard.</p><h3>Setup a New Project and Credentials</h3><p>The Permitio SDK allows API calls by initializing a permit instance with the API key, allowing subsequent calls. To get your API key, go to the dashboard and create a new project named <strong><em>Collaborative text editor</em></strong>. Proceed to copy your API Key from the development environments in use (Development/Production).</p><blockquote><em>Note: Set aside the API key until we need it in the NestJs backend.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r0INONP-tzjH1sSD.png" /></figure><p>Now, we will configure Permit for RBAC and ReBAC. They follow quite the same process with a deviation, which is that with ReBac, we’ll need to establish a relationship between resources. Here is a simple model that explains the concept better:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zapIllPlqi4e1vO8.png" /></figure><p>In the model above, the resources have roles specific to each of them. Every <strong>Folder</strong> resource contains an <strong>Admin</strong> and <strong>Editor</strong> role. If a user has an <strong>Admin</strong> role, they could perform actions specified for that role; likewise, if they have an <strong>Editor</strong> role. The same concept applies to the <strong>Document</strong> resources and demonstrates Role-based access control (RBAC).</p><p>Furthermore, every <strong>Folder</strong> resource contains a <strong>Document</strong> resource(s). By proxy, users with specific roles to a <strong>Folder</strong> resource derive certain roles to the corresponding <strong>Document</strong> resource, which shows two critical concepts in ReBAC: ownership and role derivation.</p><h3>Setting Up Resources and Actions</h3><ol><li>Navigate to <strong>Policy → Resources</strong></li><li>Click on <strong>Create a Resource</strong> or <strong>Add Resource</strong> and create a <strong><em>Folder</em></strong> and <strong><em>Document</em></strong> resource with the default actions (create, read, update, delete).</li><li>Still within the <strong>Add Resource</strong> section, add the ReBAC roles to each resource as described in the earlier image. Folder resource (Admin, Editor), Document resource (Owner, Editor, Viewer),</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qc8leX0UYpkpbfKh.png" /></figure><ol><li>We will set up a <strong>parent-child</strong> relationship between resources in the folder resource.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Eyn85zhZo8mJ0Hj1.png" /></figure><ol><li>After, go to the <strong><em>Policy Editor</em></strong> tab and check the boxes to set up the relevant actions for each resource role.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ed7p-kFoWbiNxIyz.png" /></figure><ol><li>Finally, we will create a role derivation based on the relationship between resources (parent — child). So, we navigate to the ‘<strong><em>Roles</em></strong>’ tab, then select <strong>Edit Role</strong> for the Folder#Admin. The derivation for this role will be that a user who is a Folder#Admin derives the document#owner role due to their relationship.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qg-Nvaecu4Bge8D9.png" /></figure><p>Also, create a derivation for Folder #Editor, whose derivation will be that a user who is a Folder#Editor derives the document#editor role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pGPo-EsOw-qHwFBT.png" /></figure><h3>Implementing RBAC and ReBAC with Nestjs</h3><p>Since we are done configuring our RBAC and REBAC policies on <a href="http://permit.io/">Permit.io</a>, we will implement them on our NestJs backend.</p><p>So, checkout to the backend branch with the command below:</p><pre>git checkout backend</pre><p>After, use the command below to run your development server:</p><pre>npm install</pre><p>Create a .env file at the root of your NestJs project and copy the Liveblocks secret key and the <a href="http://permit.io/">Permit.io</a> API key created earlier into it.</p><pre>PERMIT_API_KEY=&#39;Permit io API key&#39;<br>LIVE_BLOCKS_SECRET_KEY=&#39;Liveblocks secret&#39;</pre><h3>Setting up local PDP container</h3><p><a href="http://permit.io/">Permit.io</a> recommends installing the PDP (Policy-Decision-Point) via Docker to use ReBAC functionality. RBAC doesn’t require this, but we’ll use this method since we are talking about both features.</p><p>Thus, create a docker-compose.yml file in the root directory of your NestJs backend.</p><pre>version: &#39;3&#39;<br>services:<br>  pdp-service:<br>    image: permitio/pdp-v2:latest<br>    ports:<br>      - &quot;7766:7000&quot;<br>    environment:<br>      - PDP_API_KEY=permit_key_xxxxxxxxx<br>      - PDP_DEBUG=True<br>    stdin_open: true<br>    tty: true</pre><blockquote><em>Note: replace the </em><em>PDP_API_KEY with the permit API key we created when configuring </em><a href="http://permit.io/"><em>Permit.io</em></a></blockquote><p>Start your docker daemon then run the command to start the PDP service and NestJs backend.</p><pre>docker compose up -d<br>nest start --watch</pre><p>Once it’s running, you can visit http://localhost:7766 and see the response below</p><pre>{<br>  &quot;status&quot;: &quot;ok&quot;<br>}</pre><h3>Initializing <a href="http://permit.io/">Permit.io</a> SDK on NestJs backend</h3><p>In the src/permit/permit.service.ts file, we created an injectable class(check out <a href="https://docs.nestjs.com/providers">service provider</a> in NestJS) called PermitService and initialized the <a href="http://permit.io/">Permit.io</a> SDK using the code snippet:</p><pre>@Injectable()<br>export class PermitService {<br>  private permitClient: Permit;<br><br>  constructor(private configService: ConfigService) {<br>    this.permitClient = new Permit({<br>      pdp:<br>        this.configService.get&lt;string&gt;(&#39;PERMIT_PDP_URL&#39;) ||<br>        &#39;http://localhost:7766&#39;,<br>      token: this.configService.get&lt;string&gt;(&#39;PERMIT_API_KEY&#39;),<br>    });<br>  }<br>  getClient(): Permit {<br>    return this.permitClient;<br>  }<br>    ... other things<br>}</pre><h3>Syncing users with <a href="http://permit.io/">Permit.io</a> on NestJs backend</h3><p>When creating a new user on the frontend, it is reasonable to also sync the user’s credentials with <a href="http://permit.io/">Permit.io</a>. Thus, you’ll find the syncUserWithPermit method in the PermitService.</p><pre>@Injectable()<br>export class PermitService {<br>    ... other things<br>     <br>  getClient(): Permit {<br>    return this.permitClient;<br>  }<br><br>  async syncUserWithPermit(user: User): Promise&lt;any&gt; {<br>    const permit = this.getClient();<br>    const syncedUser = await permit.api.syncUser(user);<br>    return {<br>      success: true,<br>      message: `${syncedUser.email} synced with Permit.io`,<br>    };<br>  }<br>    ... other things<br>}</pre><h3>Creating <a href="http://permit.io/">Permit.io</a> resource instance using NestJs</h3><p>Having created our Resources (folder and document) on the <a href="http://permit.io/">Permit.io</a> web console, we will create an instance of the resource in NestJs. A <strong>Resource Instance</strong> is a specific, individual occurrence or object of a <strong>Resource</strong>.</p><p>So, we have a createResourceInstance method, which creates an instance when a user creates a <strong>Folder or Document</strong> on the front end.</p><pre>@Injectable()<br>export class PermitService {<br>    ... other things<br>     <br>  getClient(): Permit {<br>    return this.permitClient;<br>  }<br><br>  async createResourceInstance(resourceInstance: ResourceInstance) {<br>    try {<br>      const permit = this.getClient();<br>      const createdInstance = await permit.api.resourceInstances.create({<br>        key: resourceInstance.key,<br>        tenant: &#39;default&#39;,<br>        resource: resourceInstance.resource,<br>      });<br>      return createdInstance;<br>    } catch (error) {<br>      if (error instanceof Error) {<br>        console.log(error.message);<br>      } else {<br>        console.log(&#39;An unknown error occurred&#39;);<br>      }<br>      return null;<br>    }<br>  }<br>    ... other things<br>}</pre><p>You can find created resource instances in the <strong>Directory → Instances</strong> tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ULIlaqoFSnNbG9DP.png" /></figure><h3>Assigning <a href="http://permit.io/">Permit.io</a> resource instance using NestJs</h3><p>After creating a resource instance, the resource must be assigned to a specific user, as this will determine the user’s access to the resource. By default, the initial creator of a resource is given the topmost access.</p><p>Thus, when creating a document or folder resource, the assignResourceInstanceRoleToUser method is triggered immediately after the&#39;createResourceInstance` method.</p><pre>@Injectable()<br>export class PermitService {<br>    ... other things<br>     <br>  getClient(): Permit {<br>    return this.permitClient;<br>  }<br><br>  ... other things<br>    <br>      async assignResourceInstanceRoleToUser(<br>    resourceInstanceRole: ResourceInstanceRole,<br>  ) {<br>    try {<br>      const user = await this.getPermitioUser(resourceInstanceRole.user);<br>      if (!user) {<br>        await this.syncUserWithPermit({<br>          email: resourceInstanceRole.user,<br>          key: resourceInstanceRole.user,<br>        });<br>      }<br>      const permit = this.getClient();<br>      const assignedRole = await permit.api.roleAssignments.assign({<br>        user: resourceInstanceRole.user,<br>        role: resourceInstanceRole.role,<br>        resource_instance: resourceInstanceRole.resource_instance,<br>        tenant: &#39;default&#39;,<br>      });<br>      return assignedRole;<br>    } catch (error) {<br>      if (error instanceof Error) {<br>        console.log(error.message);<br>      } else {<br>        console.log(&#39;An unknown error occurred&#39;);<br>      }<br>      return null;<br>    }<br>  }<br>  ... other things<br>}</pre><p>You can find users assigned to a created resource instance in the <strong>Directory → Users → Edit</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6dVi7Xjt9kgHvWMX.png" /></figure><h3>Getting Resource Permission From <a href="http://permit.io/">Permit.io</a> Resource Instance Using NestJs</h3><p>There must be a mechanism for checking the permissions available to an assigned resource (document or folder). This is necessary when accessing a resource, as it lets the system know what a particular user is allowed to do within it.</p><p>Thus, when a user tries to open a document or folder, the getResourcePermissions method works, showing whether they have complete CRUD (create, read, update, delete) permission or if their access is scoped.</p><pre>@Injectable()<br>export class PermitService {<br>    ... other things<br>     <br>  getClient(): Permit {<br>    return this.permitClient;<br>  }<br><br>  ... other things<br>    <br>     async getResourcePermissions(resourcePermission: ResourcePermission) {<br>    try {<br>      const permissions = resourcePermission.permissions;<br>      const permissionMap: Record&lt;PermissionType, boolean&gt; = {<br>        read: false,<br>        create: false,<br>        delete: false,<br>        update: false,<br>      };<br>      const permit = this.getClient();<br>      for await (const permission of permissions) {<br>        permissionMap[permission] = await permit.check(<br>          resourcePermission.user,<br>          permission,<br>          resourcePermission.resource_instance,<br>        );<br>      }<br>      return permissionMap;<br>    } catch (error) {<br>      if (error instanceof Error) {<br>        console.log(error.message);<br>      } else {<br>        console.log(&#39;An unknown error occurred&#39;);<br>      }<br>      return {<br>        read: false,<br>        create: false,<br>        delete: false,<br>        update: false,<br>      };<br>    }<br>  }<br>}</pre><p>If the user doesn’t have access, they are not allowed to access the document or folder; however, if they do, they are allowed to access it and perform specific actions (create, read, update, delete) particular to that user.</p><p>In NestJs, the Injectable() decorator marks a class as a provider that can be injected into other classes. So, to use the methods in the PermitService class, we injected them into the PermitController in the src/permit/permit.controller.ts file.</p><p>Thus, we can trigger the methods in the PermitService class through specific HTTP methods (POST, GET, PUT, DELETE) from the frontend.</p><pre>@Controller(&#39;permissions&#39;)<br>export class PermitController {<br>  constructor(private permitService: PermitService) {}<br><br>  <br>  @Post(&#39;sync&#39;)<br>  async syncUserWithPermit(@Body() body: SyncUserDto): Promise&lt;any&gt; {<br>    const result = await this.permitService.syncUserWithPermit(body);<br>    if (!result.success) {<br>      throw new UnauthorizedException(&#39;Access Denied&#39;);<br>    }<br>    return {<br>      message: result.message,<br>    };<br>  }<br>  @Post(&#39;createresource&#39;)<br>  async createResourceInstance(<br>    @Body() body: CreateResourceInstanceDto,<br>  ): Promise&lt;any&gt; {<br>    const result = await this.permitService.createResourceInstance(body);<br>    if (!result) {<br>      throw new UnauthorizedException(&#39;Access Denied&#39;);<br>    }<br>    return {<br>      result: result,<br>    };<br>  }<br>  @Post(&#39;assignresourcetouser&#39;)<br>  async assignResourceInstanceRoleToUser(<br>    @Body() body: AssignResourceInstanceRoleToUserDto,<br>  ): Promise&lt;any&gt; {<br>    const result =<br>      await this.permitService.assignResourceInstanceRoleToUser(body);<br>    if (!result) {<br>      throw new UnauthorizedException(&#39;Access Denied&#39;);<br>    }<br>    return {<br>      result: result,<br>    };<br>  }<br>  @Post(&#39;getresourcepermissions&#39;)<br>  async getResourcePermissions(<br>    @Body() body: GetResourcePermissionsDto,<br>  ): Promise&lt;any&gt; {<br>    const result = await this.permitService.getResourcePermissions(body);<br>    if (!result) {<br>      throw new UnauthorizedException(&#39;Access Denied&#39;);<br>    }<br>    return {<br>      result: result,<br>    };<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*sB53eErdbB6Nu65g.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*s1Zt7XoZQkzgx1NZ.gif" /></figure><p>If you look at the video, you’ll notice the second user was added as a viewer; thus, they do not have permission to edit the document. The concept explains RBAC by showing that certain roles can perform certain actions. It also explains ReBAC by exploring the relationship between a user and a document.</p><h3>Implementing Role Derivation</h3><p>As we said earlier, role derivation occurs when a user gains certain action access to a resource due to a relationship with a parent resource.</p><p>To explain better, we must return to the <strong>Directory</strong> section in the <a href="http://permit.io/">Permit.io</a> console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NT0ueaIe6_J0R0pb.png" /></figure><p>We have a folder resource instance and a document resource instance, and we established a relationship between them. Now, we only assign the folder instance alone to a user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c0N9s4mffZgW6GEh.png" /></figure><p>Earlier, we established a couple of derivations, such as a Folder#Admin, which derives the document#owner role due to their relationship. Therefore, we can perform all the actions of a document#owner without formally assigning that document instance to a user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*w_icix-v6tm23GUD.gif" /></figure><h3>Conclusion</h3><p>Integrating modern RBAC and ReBAC systems through <a href="http://permit.io/">Permit.io</a> has improved how we handle access control in collaborative environments. By building a real-time collaborative text editor with Nest.js and Gatsby, we’ve demonstrated how to use granular and context-aware permissions to solve the limits of traditional authorization systems.</p><p>This tutorial focuses on the power of RBAC in defining multi-level roles and the flexibility of ReBAC, which leverages relationships between resources and users to assign permissions. The result is a secure and scalable system that makes sure users only access what they are authorized to while maintaining the real-time interactivity essential for collaborative tools.</p><p>With <a href="http://permit.io/">Permit.io</a>, organizations can programmatically force fine-grained access control without compromising usability or scalability. Whether you’re managing a small team or a large enterprise, this approach provides a robust framework for securing collaborative applications, making sure that access control scales alongside your organizational needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1eeb40b0a52c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Trello Clone with Advanced Permissions (Vue.js + Express + Permit.io)]]></title>
            <link>https://medium.com/@ndomaprecious95/building-a-trello-clone-with-advanced-permissions-vue-js-express-permit-io-ff81a7a72149?source=rss-04e28bde36b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff81a7a72149</guid>
            <category><![CDATA[rbac]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Ndomaprecious]]></dc:creator>
            <pubDate>Tue, 31 Dec 2024 02:26:55 GMT</pubDate>
            <atom:updated>2024-12-31T02:26:55.856Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KXNQ61n5bpdGekL3egPj0w.png" /></figure><p>Permission management in a collaborative application can be difficult to implement, and making board level access controls even more complex. Vue.js and Express are very powerful tools for building web applications, however as your application grows managing granular permissions can become unwieldy.</p><p><a href="http://permit.io/">Permit.io</a> solves this problem by providing a full blown permission management system that integrates seamlessly with your application stack. In this tutorial, we will show you how to build a Trello clone with board level permissions using Vue.js, Express and <a href="http://permit.io/">Permit.io</a>.</p><h3>Prerequisites</h3><p>Before getting started, ensure you have the following tools installed on your machine.</p><ul><li><a href="https://nodejs.org/en">Node.js (v18 or later)</a></li><li><a href="https://www.mongodb.com/try/download/community">MongoDB Database</a></li><li>VS Code or whatever code editor you like</li><li>Some knowledge of <a href="https://www.permit.io/blog/what-is-rbac">RBAC</a> and REST APIs</li></ul><h3>Building a Trello Clone with Advanced Permissions Vue.js and Express</h3><p>This tutorial explains how to create a Trello clone application that will allow users to create and manage multiple boards, organize tasks into lists, and use Drag-and-drop card functionality. We’ll also add role-based access control to control the actions users can perform on each board.</p><p>Below is a diagram for our app permission Model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z20iwwCGIQHyU-Tu8QY4Ng.png" /></figure><p>The above shows the user segments in our application, their access, and the actions they can perform.</p><h3>Creating a <a href="http://permit.io/">Permit.io</a> Project and Credentials</h3><p>To get started with <a href="http://permit.io/">Permit.io</a>, you’ll need to create a new project and generate API credentials. To do that, follow the steps below:</p><ol><li>Go to the <a href="https://app.permit.io/">Permit.io Dashboard</a> and sign up or log in.</li><li>Click on the “Create Project” button from the dashboard.</li><li>Enter a name for your project, such as “Trello Clone”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3RRytx70QmRFJdvf.png" /></figure><ol><li>Click on the <strong>Create Project</strong> button.</li><li>Once your project is created, click on the API Keys tab.</li><li>By default, <a href="http://permit.io/">Permit.io</a> provides you with two environments, Production and Development. Select your preferred environment or create a new one and <strong>Copy the API Key</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yY3gDQbwWm9-cbvV.png" /></figure><blockquote><em>Paste the API key in your .env file in the backend folder.</em></blockquote><h3>Creating RBAC Policies in <a href="http://permit.io/">Permit.io</a> UI</h3><p>Now that we have our project created, we can start creating our RBAC policies. Follow the steps below to create the policies for our application:</p><ol><li>Go to <strong>Resources → Add Resource</strong> and create a <strong>Board</strong> resource with these actions create, read, update, delete, addMember, removeMember.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zCtxG6iphsbI5GUJ.png" /></figure><p>2. Create a <strong>List</strong> resource with the create, read, update, delete actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/0*w43roSDBf7ScZkr-.png" /></figure><p>3. Create a <strong>Card</strong> resource with these actions create, read, update, delete, move.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UceaDssvFZ5Syc8k.png" /></figure><p>4. Navigate to <strong>Policy → Roles</strong> in the <a href="http://permit.io/">Permit.io</a> dashboard</p><p>5. Click “Add Roles” and create the following roles Board Admin, Board Member, Board Viewer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RXxBy_06XWwuVo3i.png" /></figure><p>6. Open the Policy Editor configure the following permission for each role and click the <strong>Save Changes</strong> button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I8-xqrpQtJAkIAxy.png" /></figure><p>From the above image, we have given the Board Admin Full access to all actions on the Board resource, while the Board Member has read, move card, create card, delete card and the Board Viewer has only read access.</p><p>7. Click on the <strong>Save</strong> button to save your policy configuration</p><p>Now go to the Directory page and add test users with different roles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F9sQW_S679HN98yE.png" /></figure><h3>Integrate <a href="http://permit.io/">Permit.io</a> with the Backend</h3><p>With the roles and permissions defined, it’s time to connect the Permit to our backend API. First, we need to clone the starter project and install dependencies.</p><pre>git clone https://github.com/preshenv/trello-clone-permit<br>cd trello-clone-permit<br>cd backend &amp;&amp; npm install &amp;&amp; cd .. &amp;&amp; cd frontend &amp;&amp; npm install</pre><p>This project includes the front built-in Vue.js and the backend API in Express.js along with MongoDB integration.</p><h3>Configuring <a href="http://permit.io/">Permit.io</a></h3><p>Next, create a config/permit.js file in your backend folder and add the Permit configuration:</p><pre>import { Permit } from &quot;permitio&quot;;<br><br>const permit = new Permit({<br> pdp: process.env.PERMIT_PDP_URL || &#39;https://cloudpdp.api.permit.io&#39;,<br> token: process.env.PERMIT_API_KEY,<br> debug: process.env.NODE_ENV !== &#39;production&#39;<br>});<br>export default permit;</pre><p>Create a .env file in the backend folder, and add the PERMIT_API_KEY and PERMIT_PDP_URL you copied earlier.</p><pre>PERMIT_API_KEY=<br>PERMIT_PDP_URL=</pre><h3>Implementing Permission Checks in the Backend</h3><p>First, let’s update the auth controller register function to sync users with <a href="http://permit.io/">Permit.io</a>:</p><pre>import permit from &quot;../config/permit.js&quot;;<br><br>export const register = async (req, res) =&gt; {<br>  try {<br>    const { email, password, name } = req.body;<br>    // Check if the user already exists<br>    const existingUser = await User.findOne({ email });<br>    if (existingUser) {<br>      return res.status(400).json({ error: &quot;Email already registered&quot; });<br>    }<br>    // Create user in database<br>    const user = await User.create({<br>      email,<br>      password: await bcrypt.hash(password, 10),<br>      name,<br>    });<br>    // Sync user with Permit.io<br>    await permit.api.syncUser({<br>      key: email,<br>      email: email,<br>      first_name: name,<br>      attributes: {},<br>    });<br>    // Assign default viewer role<br>    await permit.api.assignRole({<br>      user: email,<br>      role: &quot;BoardViewer&quot;,<br>      tenant: &quot;default&quot;,<br>    });<br>    // Generate JWT token<br>    const token = jwt.sign(<br>      { userId: user._id, email: user.email },<br>      process.env.JWT_SECRET,<br>      { expiresIn: &quot;24h&quot; }<br>    );<br>    res.status(201).json({<br>      user: {<br>        id: user._id,<br>        email: user.email,<br>        name: user.name,<br>      },<br>      token,<br>    });<br>  } catch (error) {<br>    console.error(&quot;Registration error:&quot;, error);<br>    res.status(500).json({ error: &quot;Registration failed&quot; });<br>  }<br>};</pre><p>The above code will sync the user with <a href="http://permit.io/">Permit.io</a> and assign them the viewer role by default when they register.</p><p>Now let’s create a new user and log in to see if the user is synced with <a href="http://permit.io/">Permit.io</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TU6ikPiaXoZrk-1n.png" /></figure><p>If you go to the Directory page, you’ll see that the user has been synced with <a href="http://permit.io/">Permit.io</a> and assigned the BoardViewer role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t6vUD0rfdXGFBUcW.png" /></figure><h3>Creating Middleware to Check Permissions</h3><p>Next, we’ll create a middleware function to check if a user has permission to perform an action on a resource.</p><pre>import permit from &quot;../config/permit.js&quot;;<br><br>export const checkPermission = (action, resource) =&gt; async (req, res, next) =&gt; {<br>  const { email } = req.user;<br>  if (!email) {<br>    return res.status(401).json({ error: &quot;Unauthorized&quot; });<br>  }<br>  try {<br>    const permitted = await permit.check(email, action, resource);<br>    if (!permitted) {<br>      return res.status(403).json({ error: &quot;Forbidden&quot; });<br>    }<br>    next();<br>  } catch (error) {<br>    console.error(&quot;Permission check failed:&quot;, error);<br>    res.status(500).json({ error: &quot;Internal server error&quot; });<br>  }<br>};</pre><p>In the above code, we created a middleware function that will check if a user has permission to perform an action on a resource using the <a href="http://permit.io/">permit.io</a> check function. The function takes in three arguments, the user&#39;s unique identifier, the action to be performed and the resource to be accessed. Since we used the user&#39;s email as the unique identifier, we passed it in as the identifier.</p><p>Next we’ll use this middleware to protect our routes. In the routes/boards.js file, we&#39;ll add the middleware to protect the routes.</p><pre>const { checkPermission } = require(&quot;../middleware/permissions.js&quot;);<br>const { authMiddleware } = require(&quot;../middleware/authMiddleware.js&quot;);<br>const {<br>  getBoard,<br>  updateBoard,<br>  deleteBoard,<br>  addMember,<br>  getBoards,<br>} = require(&quot;../controllers/boardController.js&quot;);<br><br>const express = require(&quot;express&quot;);<br>const router = express.Router();<br>router.get(<br>  &quot;/:boardId&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;read&quot;, &quot;Board&quot;),<br>  getBoard<br>);<br>router.put(<br>  &quot;/:boardId&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;update&quot;, &quot;Board&quot;),<br>  updateBoard<br>);<br>router.delete(<br>  &quot;/:boardId&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;delete&quot;, &quot;Board&quot;),<br>  deleteBoard<br>);<br>router.post(<br>  &quot;/:boardId/members&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;add_member&quot;, &quot;Board&quot;),<br>  addMember<br>);<br>router.get(&quot;/&quot;, authMiddleware, checkPermission(&quot;read&quot;, &quot;Board&quot;), getBoards);<br>module.exports = router;</pre><p>In the above code we are first checking if the user is authenticated using the authMiddleware middleware. Then we check if they are have permissions to create, update or delete a board using checkPermission we created earlier and pass in the action and the Permit resources.</p><p>Now if access the boards with an account does not have either BoardAdmin, BoardMember or BoardViewer role, you wont be able to access the boards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HqIJNc_0ESnlZQJn.png" /></figure><p>But if you log in with one of the accounts that have the BoardAdmin, BoardMember, or BoardViewer role, you&#39;ll be able to access the boards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*obZuF-DRAofNszUx.png" /></figure><p>Next update the card list routes to check for permissions before users are allowed to create a new list to a board.</p><pre>const express = require(&quot;express&quot;);<br>const { checkPermission } = require(&quot;../middleware/permissions.js&quot;);<br>const { authMiddleware } = require(&quot;../middleware/authMiddleware.js&quot;);<br><br>const {<br>  createList,<br>  getLists,<br>  updateList,<br>  deleteList,<br>  moveList,<br>} = require(&quot;../controllers/listController.js&quot;);<br>const router = express.Router({ mergeParams: true });<br>router.post(&quot;/&quot;, authMiddleware, checkPermission(&quot;create&quot;, &quot;list&quot;), createList);<br>router.get(&quot;/&quot;, authMiddleware, checkPermission(&quot;read&quot;, &quot;list&quot;), getLists);<br>router.put(<br>  &quot;/:id&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;update&quot;, &quot;list&quot;),<br>  updateList<br>);<br>router.delete(<br>  &quot;/:id&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;delete&quot;, &quot;list&quot;),<br>  deleteList<br>);<br>router.put(<br>  &quot;/:id/move&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;update&quot;, &quot;list&quot;),<br>  moveList<br>);<br>module.exports = router;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BhVoSwxg6H-m7_PA.png" /></figure><p>Lastly, update the backend/routes/card.js to add the Permit permission so we can control which user can create a new card in each list, update, delete or move the card to another list:</p><pre>const { checkPermission } = require(&quot;../middleware/permissions.js&quot;);<br>const { authMiddleware } = require(&quot;../middleware/authMiddleware.js&quot;);<br>const express = require(&quot;express&quot;);<br>const {<br>  createCard,<br>  getCardsByList,<br>  getCard,<br>  updateCard,<br>  deleteCard,<br>  moveCard,<br>  updateLabels,<br>  updateDueDate,<br>} = require(&quot;../controllers/cardController.js&quot;);<br><br>const router = express.Router({ mergeParams: true });<br>router.post(&quot;/&quot;, authMiddleware, checkPermission(&quot;read&quot;, &quot;card&quot;), createCard);<br>router.get(<br>  &quot;/&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;read&quot;, &quot;card&quot;),<br>  getCardsByList<br>);<br>router.get(&quot;/:id&quot;, authMiddleware, checkPermission(&quot;read&quot;, &quot;card&quot;), getCard);<br>router.put(<br>  &quot;/:id&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;update&quot;, &quot;card&quot;),<br>  updateCard<br>);<br>router.delete(<br>  &quot;/:id&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;read&quot;, &quot;card&quot;),<br>  deleteCard<br>);<br>router.put(<br>  &quot;/:id/move&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;move&quot;, &quot;card&quot;),<br>  moveCard<br>);<br>router.put(<br>  &quot;/:id/labels&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;update&quot;, &quot;card&quot;),<br>  updateLabels<br>);<br>router.put(<br>  &quot;/:id/due-date&quot;,<br>  authMiddleware,<br>  checkPermission(&quot;update&quot;, &quot;card&quot;),<br>  updateDueDate<br>);<br>module.exports = router;</pre><p>Now only perform the actions they are permitted based on the roles assigned to them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tJT0xyDTBgHNOU7y.png" /></figure><h3>Adding Permission handler to Store</h3><p>With our current implementation, when users try performing actions they are not authorized to perform, we only prevent them, but we do not show them any message to tell them why. Let’s update our frontend/store/index.js file to handle permission errors:</p><pre>// ...<br><br>api.interceptors.response.use(<br>  (response) =&gt; response,<br>  (error) =&gt; {<br>    if (error.response?.status === 401) {<br>      store.commit(<br>        &quot;SET_ERROR&quot;,<br>        &quot;You do not have permission to perform this action&quot;<br>      );<br>    }<br>    return Promise.reject(error);<br>  }<br>);<br>// ...</pre><h3>Creating Error modal component</h3><p>To display error messages to users clearly and consistently, let’s create a modal component that will show up whenever unauthorized actions are attempted. Create a new file frontend/components/ErrorModal.vue:</p><pre>&lt;!-- components/ErrorModal.vue --&gt;<br>&lt;template&gt;<br>  &lt;Transition name=&quot;modal&quot;&gt;<br>    &lt;div v-if=&quot;error&quot; class=&quot;modal-overlay&quot;&gt;<br>      &lt;div class=&quot;modal-wrapper&quot;&gt;<br>        &lt;div class=&quot;modal-container&quot;&gt;<br>          &lt;div class=&quot;modal-header&quot;&gt;<br>            &lt;div class=&quot;modal-icon&quot;&gt;<br>              &lt;svg class=&quot;error-icon&quot; viewBox=&quot;0 0 24 24&quot;&gt;<br>                &lt;path d=&quot;M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z&quot; /&gt;<br>              &lt;/svg&gt;<br>            &lt;/div&gt;<br>            &lt;h3 class=&quot;modal-title&quot;&gt;Unauthorized Action&lt;/h3&gt;<br>          &lt;/div&gt;<br><br>          &lt;div class=&quot;modal-body&quot;&gt;<br>            &lt;p&gt;{{ error }}&lt;/p&gt;<br>          &lt;/div&gt;<br>          &lt;div class=&quot;modal-footer&quot;&gt;<br>            &lt;button @click=&quot;closeError&quot; class=&quot;modal-button&quot;&gt;Close&lt;/button&gt;<br>          &lt;/div&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/Transition&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>import { computed } from &#39;vue&#39;<br>import { useStore } from &#39;vuex&#39;<br>export default {<br>  name: &#39;ErrorModal&#39;,<br>  setup() {<br>    const store = useStore()<br>    const error = computed(() =&gt; store.state.error)<br>    const closeError = () =&gt; {<br>      store.commit(&#39;CLEAR_ERROR&#39;)<br>    }<br>    return {<br>      error,<br>      closeError<br>    }<br>  }<br>}<br>&lt;/script&gt;<br>&lt;style scoped&gt;<br>#...<br>&lt;/style&gt;</pre><p>Now integrate the modal component in your App.vue:</p><pre>&lt;template&gt;<br> &lt;div id=&quot;app&quot;&gt;<br> &lt;ErrorModal /&gt;<br> &lt;router-view&gt;&lt;/router-view&gt;<br> &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>import ErrorModal from &#39;./components/ErrorModal.vue&#39;<br>export default {<br> name: &#39;App&#39;,<br> components: {<br> ErrorModal<br> }<br>}<br>&lt;/script&gt;<br>&lt;style&gt;<br>#...<br>&lt;/style&gt;</pre><p>With this we have created a reusable error modal that will display whenever the store’s error state is set, show an error message in a clean, centered modal, and include a close button to dismiss the message. The modal will automatically appear whenever an unauthorized action is attempted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pSU8eaLZdiYfM_-2.png" /></figure><h3>The Challenge with Traditional Permission Systems</h3><p>Traditional permission systems in collaborative applications often face several limitations such as:</p><ul><li>Complexity in Management which becomes more complicated as your application grows and you have different boards, users and roles to manage their permissions.</li><li>Consistency Issues: Security vulnerability comes from maintaining consistent permission check across different components and API endpoints.</li><li>Scale Limitations: Permission systems that are custom built sometimes find it hard to scale efficiently as your user base and feature set increase.</li><li>Development Overhead: A custom permission system takes a lot of development time and ongoing maintenance.</li></ul><p><a href="http://permit.io/">Permit.io</a> addresses these challenges by providing:</p><ul><li>Centralized Permission Management: One intuitive interface to define and manage all permissions</li><li>Real-time Permission Updates that allow developers instantly update access controls without deploying code changes</li><li>Scalable architecture without performance degradation, handle millions of users and permissions.</li><li>Developer-friendly SDK integration with existing applications is simple.</li></ul><h3>Conclusion</h3><p>We have come to the end of this tutorial, I’m glad you made it to this point. Throughout this tutorial, we’ve learned how to build a Trello clone application using <a href="http://permit.io/">Permit.io</a> to handle Role Based Access Control(RBAC), express.js for our backend, and Vue.js for the user interface. We started by understanding what RBAC is, the challenges, and how <a href="http://permit.io/">Permit.io</a> solves them. Then we went on to create and set up a permit project, and implement RBAC using the <a href="http://permit.io/">Permit.io</a> dashboard.</p><p>Then we built our express backend and used the Permit to secure our endpoints against unauthorized access. We then consumed the express endpoints to create a Trello clone using Vue.js.</p><p>I hope you enjoyed the journey. Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff81a7a72149" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>