{"id":21439729,"url":"https://github.com/shelepuginivan/express-jwt-auth","last_synced_at":"2026-04-11T17:46:15.024Z","repository":{"id":159358638,"uuid":"634616621","full_name":"shelepuginivan/express-jwt-auth","owner":"shelepuginivan","description":"Yet another Express.js JWT auth demo","archived":false,"fork":false,"pushed_at":"2023-05-15T18:00:38.000Z","size":88,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-18T11:43:59.062Z","etag":null,"topics":["authentication-backend","demo","express","jwt","jwt-authentication","mongodb"],"latest_commit_sha":null,"homepage":"","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/shelepuginivan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-04-30T17:50:22.000Z","updated_at":"2023-04-30T17:52:35.000Z","dependencies_parsed_at":"2023-06-12T05:00:33.851Z","dependency_job_id":null,"html_url":"https://github.com/shelepuginivan/express-jwt-auth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shelepuginivan/express-jwt-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelepuginivan%2Fexpress-jwt-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelepuginivan%2Fexpress-jwt-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelepuginivan%2Fexpress-jwt-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelepuginivan%2Fexpress-jwt-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shelepuginivan","download_url":"https://codeload.github.com/shelepuginivan/express-jwt-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelepuginivan%2Fexpress-jwt-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31689762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T13:07:20.380Z","status":"ssl_error","status_checked_at":"2026-04-11T13:06:47.903Z","response_time":54,"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":["authentication-backend","demo","express","jwt","jwt-authentication","mongodb"],"created_at":"2024-11-23T00:48:54.098Z","updated_at":"2026-04-11T17:46:14.985Z","avatar_url":"https://github.com/shelepuginivan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Express JWT Auth Demo\n\nThis is a demo of jwt authorization in Express.\n\n## Endpoints\n\n### 1. POST `/auth/register`\n\nRegister new user\n\n#### Request\n\nRequires 3 parameters (in body):\n\n* `username: string`\n* `email: string`\n* `password: string`\n\n*Request body example:*\n\n```json\n{\n  \"username\": \"John Doe\",\n  \"email\": \"email@example.com\",\n  \"password\": \"qwerty123\"\n}\n```\n\n#### Response\n\nResponse body includes following parameters:\n\n* `username: string` - username specified in request body\n* `email: string` - email specified in request body\n* `role: 'user'` - user role\n\n*Note that this endpoint does not allow to create admin user, you can create admin account in MongoDB client*\n\nAlso, server sets http-only cookie `jwt` with generated token.\n\nIf there is an account with same `username` or `email`, server responds with status 400. \n\n*Server response example:*\n\n```json\n{\n  \"username\": \"John Doe\",\n  \"email\": \"email@example.com\",\n  \"role\": \"user\"\n}\n```\n\n### 2. POST `/auth/login`\n\nLogin into existing account\n\n#### Request\n\nRequires password and either username or email:\n\n* `username: string (optional)`\n* `email: string (optional)`\n* `password: string`\n\n*Request body example:*\n\n```json\n{\n  \"username\": \"John Doe\",\n  \"password\": \"qwerty123\"\n}\n```\n\n*or*\n\n```json\n{\n  \"email\": \"email@example.com\",\n  \"password\": \"qwerty123\"\n}\n```\n\n\n#### Response\n\nResponse body includes following parameters:\n\n* `username: string` - username specified when registered\n* `email: string` - email specified when registered\n* `role: 'user' | 'admin'` - user role\n\nServer sets http-only cookie `jwt` with generated token.\n\nIf account is not created yet, server responds with status 400.\nSame happens if required fields (in body) are not provided.\n\n*Server response example:*\n\n```json\n{\n  \"username\": \"John Doe\",\n  \"email\": \"email@example.com\",\n  \"role\": \"user\"\n}\n```\n\n### 3. GET `/auth/logout`\n\nLogout from account\n\n#### Request\n\n*No parameters required*\n\n#### Response\n\nServer deletes cookie `jwt` and respond with status 200.\n\n### GET `/admin/all-users`\n\nReturns array of all users.\n\n#### Request\n\n*No parameters required in body, but jwt is required.*\n\n#### Response\n\nResponse body is array of users\n\n*Server response example:*\n\n```json\n[\n  {\n    \"username\": \"John Doe\",\n    \"email\": \"email@example.com\",\n    \"role\": \"user\"\n  },\n  {\n    \"username\": \"Jane Doe\",\n    \"email\": \"another@example.com\",\n    \"role\": \"admin\"\n  }\n]\n```\n\nIf token is not provided (user is not authenticated) or user role (which is determined by token) is not `'admin'`, server responds with status 403.\n\n## How to run\n\nClone this repository\n\n```shell\ngit clone https://github.com/shelepuginivan/express-jwt-auth.git\ncd shrinker\n```\n\nSetup config file\n```shell\ncp .env.example .env\nvi .env\n```\n\nBuild the project\n\n```shell\nnpm install\nnpm run build\n```\n\nRun server\n\n```shell\nnpm start\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshelepuginivan%2Fexpress-jwt-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshelepuginivan%2Fexpress-jwt-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshelepuginivan%2Fexpress-jwt-auth/lists"}