{"id":23893531,"url":"https://github.com/devlopersabbir/dev-auth-middleware-jwt","last_synced_at":"2026-06-17T03:31:12.737Z","repository":{"id":152789888,"uuid":"627097033","full_name":"devlopersabbir/dev-auth-middleware-jwt","owner":"devlopersabbir","description":"Auth middleware with JWT refresh token","archived":false,"fork":false,"pushed_at":"2026-04-23T19:41:58.000Z","size":1222,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-06T01:07:51.119Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devlopersabbir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-12T19:23:27.000Z","updated_at":"2026-04-23T19:42:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"4407c54b-6154-45b1-9b45-189af21a0a27","html_url":"https://github.com/devlopersabbir/dev-auth-middleware-jwt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devlopersabbir/dev-auth-middleware-jwt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlopersabbir%2Fdev-auth-middleware-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlopersabbir%2Fdev-auth-middleware-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlopersabbir%2Fdev-auth-middleware-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlopersabbir%2Fdev-auth-middleware-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devlopersabbir","download_url":"https://codeload.github.com/devlopersabbir/dev-auth-middleware-jwt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlopersabbir%2Fdev-auth-middleware-jwt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34433085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"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":"2025-01-04T14:27:50.748Z","updated_at":"2026-06-17T03:31:12.721Z","avatar_url":"https://github.com/devlopersabbir.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/devlopersabbir"],"categories":[],"sub_categories":[],"readme":"\n  [![npm](https://img.shields.io/npm/v/dev-auth-middleware-jwt?style=flat-square\u0026logo=npm)](https://www.npmjs.com/package/dev-auth-middleware-jwt)\n  [![npm](https://img.shields.io/npm/l/dev-auth-middleware-jwt?style=flat-square\u0026logo=npm)](https://github.com/devlopersabbir/dev-auth-middleware-jwt/blob/main/LICENSE)\n  [![GitHub issues](https://img.shields.io/github/issues/devlopersabbir/dev-auth-middleware-jwt?style=flat-square\u0026logo=github)](https://github.com/devlopersabbir/dev-auth-middleware-jwt/issues)\n  [![GitHub stars](https://img.shields.io/github/stars/devlopersabbir/dev-auth-middleware-jwt?style=flat-square\u0026logo=github)](https://github.com/devlopersabbir/dev-auth-middleware-jwt/stargazers)\n  [![npm](https://img.shields.io/npm/dt/dev-auth-middleware-jwt?style=flat-square\u0026logo=npm)](https://www.npmjs.com/package/dev-auth-middleware-jwt)\n\n\n# dev-auth-middleware-jwt\nA powerful JWT authentication middleware for Node.js to create accesstoken, refreshtoken and also able to validate both tokens.\n\n  This middleware provides a simple and secure way to authenticate HTTP requests using JSON Web Tokens (JWTs). It can be easily integrated into any Node.js application and supports a variety of authentication strategies, including bearer tokens and cookie-based authentication. Finally, this library will help us to generate access \u0026 refresh tokens also able to validate\nFor more information on how to use the middleware, please refer to the [documentation](https://github.com/devlopersabbir/dev-auth-middleware-jwt#readme).\n\n## INSTALLATION\n\n```console\n$ npm i dev-auth-middleware-jwt --save\n```\n\nor if you are use `yarn` then just run this code\n\n```console\n$ yarn add dev-auth-middleware-jwt --save\n```\n\n## REQUIRED TASK\n\n- We have to create a `.env` file in the root project directory to store our all of `environment` variables.\n- Create all variables following the down below code example.\n\n```console\nACCESS_TOKEN_SECRET=key //use your secret key\nACCESS_TOKEN_EXPIRES_IN=1d //modify as you need eg: 60s, 1m, 1h, 7d\n\nREFRESH_TOKEN_SECRET=key //use your secret key\nREFRESH_TOKEN_EXPIRES_IN=1d //modify as you need eg: 60s, 1m, 1h, 7d\n```\n\n- That is required\n\n## USAGES\n\nFirstly, just import this package using\n\n```ts\nimport { JWT, Validate } from \"dev-auth-middleware-jwt\";\n```\n\nNow it's ready to use.\n\nIf you want you try this template. I just try to explement this package features and show...\n\n```ts\nimport express, { Request, Response } from \"express\";\nimport dotenv from \"dotenv\";\nimport { JwtPayload } from \"jsonwebtoken\";\ndotenv.config();\nimport { JWT, Validate } from \"dev-auth-middleware-jwt\";\n\ndeclare module \"express\" {\n  interface Request {\n    user?: any;\n  }\n}\n\nconst app = express();\napp.use(express.json());\n\nlet refreshTokens: any = [];\napp.post(\"/\", async (req: Request, res: Response) =\u003e {\n  const { username, password } = req.body;\n  try {\n    const payload: JwtPayload = {\n      id: \"4234124123423535\",\n      username,\n    };\n    const accessToken = JWT.generateAccessToken(payload);\n    const refreshToken = JWT.generateRefreshToken(payload);\n    refreshTokens.push(refreshToken);\n\n    // response\n    res.status(200).json({\n      data: {\n        accessToken,\n        refreshToken,\n      },\n    });\n  } catch (error) {\n    console.log(error);\n    res.status(500).json({ message: \"Something went wrong!\", error });\n  }\n});\n\napp.post(\"/pro\", Validate.accessToken, async (req: Request, res: Response) =\u003e {\n  if (req.user) {\n    res.json({\n      data: {\n        user: req.user,\n      },\n    });\n  } else {\n    res.json({ data: { message: \"User not found\" } });\n  }\n});\n\napp.post(\n  \"/get-ref\",\n  Validate.refreshToken,\n  async (req: Request, res: Response) =\u003e {\n    console.log(req.user);\n    if (req.user) {\n      res.json({\n        data: {\n          user: req.user,\n        },\n      });\n    } else {\n      res.json({ data: { message: \"User not found\" } });\n    }\n  }\n);\n\nconst PORT = process.env.PORT || 4000;\napp.listen(PORT, () =\u003e console.log(`🚀 Server is running at ${PORT}`));\n```\n\n#### Author\n\nThis package was created by [Sabbir Hossain Shuvo](https://www.showwcase.com/devlopersabbir). And the GitHub profile is [https://github.com/devlopersabbir](https://github.com/devlopersabbir).\n\n\n#### LICENSE\n\nMIT\n\nFor support just [Buy Me A Coffee](https://www.buymeacoffee.com/devlopersabbir)\n[https://www.buymeacoffee.com/devlopersabbir](https://www.buymeacoffee.com/devlopersabbir)\n\n## Contributing\nIf you would like to contribute to this project, please follow these steps:\n1. Fork this repository.\n2. Clone your forked repository:\n3. For your changes:\n4. Make your changes, commit them, and push them to your forked repository:\n5. Create a pull request on this repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlopersabbir%2Fdev-auth-middleware-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevlopersabbir%2Fdev-auth-middleware-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlopersabbir%2Fdev-auth-middleware-jwt/lists"}