{"id":22489160,"url":"https://github.com/arifimran5/jwt-auth-fastify","last_synced_at":"2026-01-18T07:30:24.627Z","repository":{"id":210412953,"uuid":"694212600","full_name":"arifimran5/jwt-auth-fastify","owner":"arifimran5","description":"token based auth with fastify, prisma, jwt and typescript","archived":false,"fork":false,"pushed_at":"2023-12-02T15:26:53.000Z","size":30,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-12-02T16:29:13.026Z","etag":null,"topics":["fastify","jwt","typescript","zod"],"latest_commit_sha":null,"homepage":"","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/arifimran5.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}},"created_at":"2023-09-20T14:46:34.000Z","updated_at":"2023-12-02T16:29:16.425Z","dependencies_parsed_at":"2023-12-02T16:39:19.411Z","dependency_job_id":null,"html_url":"https://github.com/arifimran5/jwt-auth-fastify","commit_stats":null,"previous_names":["arifimran5/jwt-auth-fastify"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arifimran5%2Fjwt-auth-fastify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arifimran5%2Fjwt-auth-fastify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arifimran5%2Fjwt-auth-fastify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arifimran5%2Fjwt-auth-fastify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arifimran5","download_url":"https://codeload.github.com/arifimran5/jwt-auth-fastify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228500221,"owners_count":17930020,"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","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":["fastify","jwt","typescript","zod"],"created_at":"2024-12-06T17:19:20.254Z","updated_at":"2026-01-18T07:30:24.542Z","avatar_url":"https://github.com/arifimran5.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"## Token based authentication with Fastify, JWT and Prisma\n\nThis is a repository for a JWT authentication service using **Fastify**, **Prisma**, **sqlite db** and **TypeScript**. It allows users to register, login, logout, and get a list of users from a sqlite database. It uses bcrypt for hashing passwords, zod for validating schemas, and fastify-jwt for generating and verifying tokens.\n\n## App structure\n\n```\njwt-auth-fastify\n├── package.json\n├── tsconfig.json\n├── prisma\n│ ├── migrations\n│ └── schema.prisma\n└── src\n  ├── app.ts\n  ├── modules\n  │  └── user\n  │     ├── user.controller.ts\n  │     ├── user.route.ts\n  │     └── user.schema.ts\n  └── utils\n    ├── prisma.ts\n    └── types.ts\n```\n\n## Installation\n\nTo install this project, you need to have Node.js, pnpm installed on your machine.\n\nThen, run the following commands in your terminal:\n\n```bash\n# Clone the repository\ngit clone https://github.com/arifimran5/jwt-auth-fastify.git\n\n# Change directory\ncd jwt-auth-fastify\n\n# Install dependencies\npnpm install\n\n# Run migrations\npnpm prisma migrate dev\n\n# Start the development server\npnpm dev\n```\n\nThe server will run on http://localhost:8000 by default.\n\n## Usage\n\nThe project exposes four endpoints for user authentication:\n\n- GET /: returns a list of users with their name, id, and email. Requires an access token in the cookie or the authorization header.\n- POST /register: creates a new user with the given name, email, and password. Returns the user data and an access token.\n- POST /login: logs in an existing user with the given email and password. Returns the user data and an access token.\n- DELETE /logout: logs out the current user by clearing the access token cookie.\n\nYou can use a tool like Postman Here are some examples:\n\n- GET /: returns a list of users with their name, id, and email. Requires an access token in the cookie or the authorization header.\n- POST /register: creates a new user with the given name, email, and password. Returns the user data and an access token.\n- POST /login: logs in an existing user with the given email and password. Returns the user data and an access token.\n- DELETE /logout: logs out the current user by clearing the access token cookie.\n\n## Parameters\n\nThe API accepts the following parameters in the request body:\n\n- name: the name of the user. Required for the /register endpoint. Must be a string.\n- email: the email of the user. Required for the /register and /login endpoints. Must be a valid email address.\n- password: the password of the user. Required for the /register and /login endpoints. Must be a string with at least 6 characters.\n\n## Dependencies\n\nThe project uses the following dependencies:\n\n- @fastify/cookie: for setting and clearing cookies\n- @fastify/jwt: for generating and verifying JSON web tokens\n- @prisma/client: for interacting with the PostgreSQL database\n- bcrypt: for hashing and comparing passwords\n- fastify: for creating the web server\n- fastify-zod: for validating request and response schemas\n- zod: for defining schemas\n\nThe project also uses the following dev dependencies:\n\n- @types/bcrypt: for TypeScript type definitions for bcrypt\n- @types/node: for TypeScript type definitions for Node.js\n- prisma: for managing the database schema and migrations\n- tsx: for compiling and watching TypeScript files\n- typescript: for writing and checking TypeScript code\n\n## Contribution\n\nIf you want to contribute to this project, you can fork the repository and create a pull request with your changes. Please follow the code style and conventions of the project, and write clear and concise commit messages. You can also report any issues or suggestions on the GitHub issue tracker.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farifimran5%2Fjwt-auth-fastify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farifimran5%2Fjwt-auth-fastify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farifimran5%2Fjwt-auth-fastify/lists"}