{"id":27148184,"url":"https://github.com/dias1c/casbin-js","last_synced_at":"2026-02-26T03:41:23.474Z","repository":{"id":222911891,"uuid":"758097757","full_name":"Dias1c/casbin-js","owner":"Dias1c","description":"🔐 Simple library that supports access control models like ACL, RBAC, ABAC in Frontend Javascript","archived":false,"fork":false,"pushed_at":"2025-03-14T06:12:29.000Z","size":110,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-19T16:56:40.290Z","etag":null,"topics":["abac","acl","auth","authorization","authorizer","authz","casbin","casbin-frontend","casbin-js","permissions","rbac"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@diaskappassov/casbin-js","language":"TypeScript","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/Dias1c.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOGS.md","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":"2024-02-15T16:11:50.000Z","updated_at":"2025-03-23T15:50:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"a511963c-9638-49bf-b3dd-9ee8f9eb974b","html_url":"https://github.com/Dias1c/casbin-js","commit_stats":null,"previous_names":["dias1c/casbin-js"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Dias1c/casbin-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dias1c%2Fcasbin-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dias1c%2Fcasbin-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dias1c%2Fcasbin-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dias1c%2Fcasbin-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dias1c","download_url":"https://codeload.github.com/Dias1c/casbin-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dias1c%2Fcasbin-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29848654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T22:37:40.667Z","status":"online","status_checked_at":"2026-02-26T02:00:06.774Z","response_time":89,"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":["abac","acl","auth","authorization","authorizer","authz","casbin","casbin-frontend","casbin-js","permissions","rbac"],"created_at":"2025-04-08T11:53:07.709Z","updated_at":"2026-02-26T03:41:23.438Z","avatar_url":"https://github.com/Dias1c.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# casbin-js\n\n🔐 Simple library that supports access control models like ACL, RBAC, ABAC in Frontend Javascript.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"ts\" src=\"https://badgen.net/badge/-/TypeScript?icon=typescript\u0026label\u0026labelColor=blue\u0026color=555555\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@diaskappassov/casbin-js\"\u003e\n    \u003cimg alt=\"NPM package version\" src=\"https://img.shields.io/npm/v/@diaskappassov/casbin-js\"/\u003e\n    \u003cimg alt=\"NPM package downloads count\" src=\"https://img.shields.io/npm/dy/@diaskappassov/casbin-js?label=Downloads\u0026logo=npm\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/Dias1c/casbin-js/\"\u003e\n    \u003cimg alt=\"Visit package GitHub page\" src=\"https://img.shields.io/github/stars/Dias1c/casbin-js?style=social\u0026label=GitHub\u0026maxAge=2592000\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003e [!NOTE]\n\u003e - Changelogs [here](./CHANGELOGS.md).\n\u003e - Read more about casbin [here](https://casbin.org/docs/overview).\n\n## Installation\n\n```\nnpm i --save-exact @diaskappassov/casbin-js@0.6\n```\n\n## Usage\n\nYou can see all usage examples in [examples directory](./examples).\n\n- [react example in codesandbox with preview](https://codesandbox.io/p/sandbox/laughing-snowflake-ychqzq)\n- [react typescript example code](./examples/react.tsx)\n- [vanilla typescript example file](./examples/vanilla.ts)\n\n### Initialize Authorizer\n\nTo understand what the `model` and `policy` read https://casbin.org/docs/syntax-for-models/\n\n```ts\nimport { CAuthorizer } from \"@diaskappassov/casbin-js\";\n\nconst model = `\n# Request definition\n[request_definition]\n# Can subject, do_action, on_object\nr = sub, act, obj\n\n# Policy definition\n[policy_definition]\np = sub, act, obj\n\n# Role definition\n[role_definition]\ng = _, _\n\n# Policy effect\n[policy_effect]\ne = some(where (p.eft == allow))\n\n# Matchers\n[matchers]\nm = g(r.sub, p.sub) \u0026\u0026 r.obj == p.obj \u0026\u0026 r.act == p.act\n`;\n\nconst policy = [\n  [\"p\", \"cat\", \"walk\", \"ground\"],\n  [\"p\", \"cat\", \"run\", \"ground\"],\n  [\"p\", \"cat\", \"swim\", \"water\"],\n  [\"p\", \"cat\", \"breathe\", \"air\"],\n\n  [\"p\", \"bird\", \"fly\", \"air\"],\n  [\"p\", \"bird\", \"breathe\", \"air\"],\n  [\"p\", \"bird\", \"walk\", \"ground\"],\n\n  [\"p\", \"fish\", \"swim\", \"water\"],\n  [\"p\", \"fish\", \"breathe\", \"water\"],\n];\n\nconst Authorizer = new CAuthorizer();\n\nAuthorizer.init(model, policy);\n```\n\n### Check permissions\n\nYou can check permissions with `can`, `canAll`, `canAny` methods, but before that YOU MUST INITIALIZE `Authorizer`.\n\n\u003e [!IMPORTANT]\n\u003e The order of your request elements must follow the rules which you set in `model`. See more: https://casbin.org/docs/syntax-for-models#request-definition\n\n#### Check permissions with `can` method\n\n\u003e [!WARNING]\n\u003e If the `Authorizer` is not initialized it throws error\n\n```ts\nawait Authorizer.can([\"fish\", \"fly\", \"air\"]); // false\nawait Authorizer.can([\"fish\", \"swim\", \"ground\"]); // false\nawait Authorizer.can([\"fish\", \"swim\", \"water\"]); // true\nawait Authorizer.can([\"cat\", \"swim\", \"water\"]); // true\nawait Authorizer.can([\"bird\", \"run\", \"ground\"]); // false\nawait Authorizer.can([\"cat\", \"run\", \"ground\"]); // true\n```\n\n#### Check permissions with `canAll` method\n\n```ts\n// returns `false` cause one of conditions returned `false`\nawait Authorizer.canAll([\n  [\"cat\", \"breathe\", \"air\"],\n  [\"fish\", \"breathe\", \"air\"],\n]);\n\n// returns `true` cause all conditions returned `true`\nawait Authorizer.canAll([\n  [\"cat\", \"breathe\", \"air\"],\n  [\"bird\", \"breathe\", \"air\"],\n]);\n```\n\n#### Check permissions with `canAny` method\n\n```ts\n// returns `true` cause one of conditions returned `true`\nawait authorizer.canAny([\n  [\"cat\", \"breathe\", \"air\"],\n  [\"fish\", \"breathe\", \"air\"],\n]);\n\n// returns `false` cause all conditions returned `false`\nawait authorizer.canAny([\n  [\"cat\", \"fly\", \"air\"],\n  [\"fish\", \"fly\", \"air\"],\n]);\n```\n\n## Author\n\n- [Dias1c - Dias Kappassov](https://github.com/Dias1c)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdias1c%2Fcasbin-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdias1c%2Fcasbin-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdias1c%2Fcasbin-js/lists"}