{"id":21011237,"url":"https://github.com/javascriptke/express-mongoose-user-permissions","last_synced_at":"2026-04-21T20:02:11.543Z","repository":{"id":178843912,"uuid":"465295362","full_name":"javascriptke/express-mongoose-user-permissions","owner":"javascriptke","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-18T21:43:29.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-30T00:56:23.745Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/javascriptke.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":"2022-03-02T12:25:05.000Z","updated_at":"2022-03-03T10:07:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"da99339a-b414-4777-9203-600eeb27e8b3","html_url":"https://github.com/javascriptke/express-mongoose-user-permissions","commit_stats":null,"previous_names":["javascriptke/express-mongoose-user-permissions"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/javascriptke/express-mongoose-user-permissions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javascriptke%2Fexpress-mongoose-user-permissions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javascriptke%2Fexpress-mongoose-user-permissions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javascriptke%2Fexpress-mongoose-user-permissions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javascriptke%2Fexpress-mongoose-user-permissions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/javascriptke","download_url":"https://codeload.github.com/javascriptke/express-mongoose-user-permissions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javascriptke%2Fexpress-mongoose-user-permissions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32108187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-11-19T09:27:11.438Z","updated_at":"2026-04-21T20:02:11.521Z","avatar_url":"https://github.com/javascriptke.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node js Auth Roles with MongoDb and typescript\nWhat will you learn from this?\n---\n- Mongoose custom methods\n- Mongoose static methods\n- Integrating mongoose with `Typescript`\n- Virtual fields\n- building permission system with `Node js`\n...\n\nIn this setup the permissions are executed using bitwise operators ie. (`AND`|`OR`|`XOR`) -\u003e `~\u0026|^`\n\nIt's effectiveness is the flexibility to add different permissions(Custom permissions).\n\nI've emulated a blog site permissions that has the following roles:\n\n- Comment on a post\n- View a post\n- Like a given post\n- Moderate the comment,likes on a post i.e Moderatoe\n- Overall Admin (The platform owner with all permissions)\n\n\n-------\n| Role issued| Role Name | Role value |\n| :-------------------------------------------------------------- | :------- | :--------: |\n| Read only, No permission provided                               |   None    |     0      |\n| View on a post                                                  |   VIEW    |     1      |\n| Comment on a post                                               |  COMMENT  |     2      |\n| Like a post                                                     |   LIKE    |     4      |\n| Moderate on posts activities                                    | MODERATE  |     8      |\n| Administrate the blog activities and the overal site activities |   ADMIN   |     16     |\n---\n\nOn cloning this repo use the `.env.example` to setup the `.env` file \n\n\n### Development\n\nOnce cloned\n```sh\n$ cd \u003cdir_name\u003e\n$ yarn # To install all the dependencie\n$ yarn run dev:start\n$\n```\nWhen the project is running the first thing you need populate all the roles in the project\n\nA  `POST` request to the  `{BASE_URL}/roles/insert` route to populate the given roles declared\n\nTo get the present roles run a get request on the \n`{BASE_URL}/roles` route.\n\nMuch can be extended from this setup:\n\nEmulation of the same: \nThis is a class base way of implementing the Model and adding, removing, resetiting permissions\n\n```ts\nclass Role {\n  private _permissions: number=0;\n  private _name: string=\"\";\n\n  constructor(name:string) {\n    this._permissions = 0;\n    this._name=name\n    \n  }\n\n  public get permissions(): number {\n    return this._permissions;\n  }\n\n  public get name(): string {\n    return this._name;\n  }\n\n   //* Add user role\n  addPermission = (permission: number): void =\u003e {\n    if (!this.hasPermission(permission)) {\n      this._permissions += permission;\n    }\n  };\n   // * Remove user role\n  removePermission = (permission: number): void =\u003e {\n    if (this.hasPermission(permission)) {\n      this._permissions -= permission;\n    }\n  };\n\n   //* Check is a user has a given role\n  hasPermission = (permission: number): boolean =\u003e {\n    return (this.permissions \u0026 permission) === permission;\n  };\n   //* Reset all permissions\n  resetPermissions = (): void =\u003e {\n    this._permissions = 0;\n  };\n}\n\nenum  Perms {\n  FOLLOW = 1,\n  COMMENT = 2,\n  WRITE = 4,\n  MODERATE = 8,\n  ADMIN = 16,\n}\n\nconst role1 = new Role(\"User\");\nrole1.addPermission(Perms.WRITE);\nrole1.addPermission(Perms.COMMENT);\nrole1.removePermission(Perms.FOLLOW);\n\nconsole.log(role1.hasPermission(Perms.MODERATE));\n```\n\nThe project is open for Development and anyone wishing to help extend the codebase. I would highly appreciate\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavascriptke%2Fexpress-mongoose-user-permissions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavascriptke%2Fexpress-mongoose-user-permissions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavascriptke%2Fexpress-mongoose-user-permissions/lists"}