{"id":22802731,"url":"https://github.com/buffolander/react-gatekeeper","last_synced_at":"2025-08-02T09:33:12.124Z","repository":{"id":143745430,"uuid":"354830464","full_name":"buffolander/react-gatekeeper","owner":"buffolander","description":"Simplified Role-Based Access Control for React applications","archived":false,"fork":false,"pushed_at":"2021-04-05T17:24:59.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-01T14:52:47.591Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/buffolander.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-05T12:41:08.000Z","updated_at":"2023-03-05T07:58:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"4dbe044c-d980-4119-bb3f-545cb0738c04","html_url":"https://github.com/buffolander/react-gatekeeper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/buffolander/react-gatekeeper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buffolander%2Freact-gatekeeper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buffolander%2Freact-gatekeeper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buffolander%2Freact-gatekeeper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buffolander%2Freact-gatekeeper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buffolander","download_url":"https://codeload.github.com/buffolander/react-gatekeeper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buffolander%2Freact-gatekeeper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268362943,"owners_count":24238543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-12T09:07:08.485Z","updated_at":"2025-08-02T09:33:12.092Z","avatar_url":"https://github.com/buffolander.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Gatekeeper\n\nA simplified solution for role-based access control and conditional component rendering on React applications.\n\nThe Gatekeeper manages access to views and conditional component rendering comparing claims found in users' JWT access tokens against a set of authorized (compound) roles. Claims hold the role(s) of each user within the application. Compound roles combine groups that users are associated with (orgTypes) and their role within each group (role).\n\nTo clarify the concept, consider John who's a sales manager at a retail company. His claims might include a global scope within the company, as well as an scope specific to the sales department. His decoded JWT token would look something like this:\n\n```\n{\n  \"sub\": \"1234567890\",\n  \"name\": \"John Doe\",\n  \"iat\": 1516239022\n  \"departments\": [{ // 'organizations' is John's root claims property\n    \"department\": \"global\", // 'department' is the orgType property on each claim\n    \"role\": \"employee\" // 'role' is orgRole property on each claim\n  }, {\n    \"department\": \"sales\",\n    \"role\": \"manager\"\n  }]\n}\n```\n\nTherefore, John's compound roles within the company could be summarized as `['global:employee', 'sales:manager']`.\n\n## Sample Quick Start\n\nThe easiest way to start using React Gatekeeper right away is learning from an example.\n\n```\n# Dummy application structure\n|\n|- \u003cComponents\u003e\n  |- IndividualPerformance.js\n  |- TeamPerformance.js\n|- \u003cViews\u003e\n  |- Intranet.js\n  |- SalesTeam.js\n  |- SignIn.js\n  |- 404.js\n|- App.js\n|- Gatekeeper.js\n```\n\n### Step 1: Initialize your Gatekeeper\n\n```javascript\n// ./Gatekeeper.js\nimport Gatekeeper from 'react-gatekeeper'\n\nconst gatekeeper = new Gatekeeper({\n  rootClaimsProperty: 'departments',\n  claimOrgTypeProp: 'department',\n  claimOrgRoleProp: 'role',\n})\n\ngatekeeper.addRule({\n  route: '/intranet',\n  whitelist: ['global:employee'],\n})\n/* a service provider holding a claim 'global:ext' wouldn't have access to the company's intranet */\ngatekeeper.addRule({\n  route: '/sales-team',\n  whitelist: ['sales:*'],\n})\n\nexport default gatekeeper\n```\n\n### Step 2: Layout your application routes with the Gatekeeper\n\n```javascript\n// ./App.js\nimport React from 'react'\nimport {\n  BrowserRouter, Switch, Route,\n} from 'react-router-dom'\n\nimport gatekeeper from './Gatekeeper'\nimport Intranet from './Views/Intranet'\nimport SalesTeam from './Views/SalesTeam'\nimport SignIn from './Views/SignIn'\nimport NotFound from './Views/404'\n\nfunction App() {\n  const accessToken = undefined /* retrieve the user accessToken */\n  gatekeeper.setUserToken(accessToken)\n\n  const restrictedRoutes = [{\n    path: '/intranet',\n    component: Intranet,\n  }, {\n    path: '/sales-team',\n    component: SalesTeam,\n  }]\n\n  return (\n    \u003cBrowserRouter\u003e\n        \u003cSwitch\u003e\n          {restrictedRoutes.map((route) =\u003e (\n            gatekeeper.routeGate(route.path)\n              ? \u003cRoute path={route.path} component={route.component} /\u003e\n              : \u003cRoute path={route.path} component={!accessToken ? SignIn : NotFound} /\u003e\n          ))}\n          \u003cRoute path='/sign-in*' component={SignIn} /\u003e\n          \u003cRoute path='*' component={NotFound} /\u003e\n        \u003c/Switch\u003e\n    \u003c/BrowserRouter\u003e\n  )\n}\n\nexport default App\n```\n\n### Step 3: Add conditional rendering to your view components\n\n```javascript\n// ./Views/SalesTeam.js\nimport React from 'react'\n\nimport gatekeeper from '../Gatekeeper'\nimport IndividualPerformance from '../Components/IndividualPerformance'\nimport TeamPerformance from '../Components/TeamPerformance'\n\nfunction SalesTeam() {\n  // TeamPerformance will be rendered only to sales managers\n  // IndividualPerformance will be rendered only to sales reps\n  return(\u003cdiv\u003e\n    {gatekeeper.componentGate(['sales:manager'], TeamPerformance)}\n    {gatekeeper.componentGate(['sales:rep'], IndividualPerformance)}\n  \u003c/div\u003e)\n}\n\nexport default SalesTeam\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuffolander%2Freact-gatekeeper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuffolander%2Freact-gatekeeper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuffolander%2Freact-gatekeeper/lists"}