{"id":21038366,"url":"https://github.com/qlaffont/fastify-auth-prisma","last_synced_at":"2026-03-11T01:02:18.708Z","repository":{"id":57753141,"uuid":"526096854","full_name":"qlaffont/fastify-auth-prisma","owner":"qlaffont","description":"Fastify plugin with Prisma to make simple \u0026 secure authentification middleware.","archived":false,"fork":false,"pushed_at":"2024-07-16T07:09:24.000Z","size":5898,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-28T20:45:14.372Z","etag":null,"topics":["authentication","fastify","prisma","simple","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fastify-auth-prisma","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/qlaffont.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.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,"zenodo":null}},"created_at":"2022-08-18T07:07:04.000Z","updated_at":"2024-07-16T07:09:27.000Z","dependencies_parsed_at":"2024-02-20T02:25:03.083Z","dependency_job_id":"247430c3-bff7-4d14-bbf8-a4608e827dce","html_url":"https://github.com/qlaffont/fastify-auth-prisma","commit_stats":null,"previous_names":["flexper/fastify-auth-prisma"],"tags_count":737,"template":false,"template_full_name":null,"purl":"pkg:github/qlaffont/fastify-auth-prisma","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qlaffont%2Ffastify-auth-prisma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qlaffont%2Ffastify-auth-prisma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qlaffont%2Ffastify-auth-prisma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qlaffont%2Ffastify-auth-prisma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qlaffont","download_url":"https://codeload.github.com/qlaffont/fastify-auth-prisma/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qlaffont%2Ffastify-auth-prisma/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30364608,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"ssl_error","status_checked_at":"2026-03-10T21:40:59.357Z","response_time":106,"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","fastify","prisma","simple","typescript"],"created_at":"2024-11-19T13:31:42.099Z","updated_at":"2026-03-11T01:02:18.646Z","avatar_url":"https://github.com/qlaffont.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Maintainability](https://api.codeclimate.com/v1/badges/6e747003545ffe76ceac/maintainability)](https://codeclimate.com/github/qlaffont/fastify-auth-prisma/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/6e747003545ffe76ceac/test_coverage)](https://codeclimate.com/github/qlaffont/fastify-auth-prisma/test_coverage) ![npm](https://img.shields.io/npm/v/fastify-auth-prisma) ![npm](https://img.shields.io/npm/dm/fastify-auth-prisma) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/fastify-auth-prisma) ![NPM](https://img.shields.io/npm/l/fastify-auth-prisma)\n\n# Fastify-Auth-Prisma\n\nFastify plugin with Prisma to make simple \u0026 secure authentification middleware. Old Owner: [@flexper](https://github.com/flexper)\n\n## Usage\n\n```bash\n\npnpm install fastify-auth-prisma unify-fastify prisma @prisma/client\n\n```\n\n[Initialize Prisma](https://www.prisma.io/docs/getting-started) and create a similar schema.prisma\n\n```prisma\nmodel Token {\n  id           String @id @unique @default(uuid())\n  refreshToken String\n  accessToken  String\n\n  owner   User   @relation(fields: [ownerId], references: [id])\n  ownerId String\n\n  createdAt DateTime @default(now())\n}\n\nmodel User {\n  id            String  @id @unique @default(uuid())\n\n  tokens          Token[]\n\n  createdAt       DateTime         @default(now())\n  updatedAt       DateTime         @updatedAt\n}\n\n```\n\nAdd your plugin in your fastify server\n\n```typescript\nimport fastify from 'fastify';\nimport { PrismaClient, User } from '@prisma/client';\nimport unifyFastifyPlugin from 'unify-fastify';\nimport {fastifyAuthPrismaPlugin} from 'fastify-auth-prisma';\n\nconst prisma = new PrismaClient();\nconst server = fastify();\n\ndeclare module 'fastify' {\n  interface FastifyRequest {\n    connectedUser?: User;\n  }\n}\n\nawait server.register(unifyFastifyPlugin);\n\nawait server.register(fastifyAuthPrismaPlugin, {\n  config: [{url: \"/public/*\", method: 'GET'}],\n  prisma,\n  secret: process.env.JWT_ACCESS_SECRET, // Recommanded to use an external variable but you can use any generated string\n});\n```\n\n## API\n\n### fastifyAuthPrismaPlugin\n\n**Options**\n\n| Field Name     | Type                                             | Description                                                                        |\n| -------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------- |\n| config         | {url: string, method: HttpMethods}[]             | Specify which urls are allowed without valid token                                 |\n| cookieIsSigned | boolean [OPTIONAL]                               | If cookies is used, precise if value is signed                                     |\n| secret         | string                                           | Secret use for accessToken generation                                              |\n| prisma         | Prisma Client                                    |                                                                                    |\n| userValidation | (user: Prisma[User]) =\u003e Promise\u003cvoid\u003e [OPTIONAL] | Function to run to add userValidation on request (ex: isBanned / isEmailValidated) |\n\n**Return**\n\n| Field Name    | Type           | Description                   |\n| ------------- | -------------- | ----------------------------- |\n| connectedUser | Prisma[\"User\"] | Connected user                |\n| isConnected   | boolean        | Return if a user is connected |\n\n### createUserToken(prisma)(userId, {secret, refreshSecret, accessTokenTime, refreshTokenTime})\n\n**Options**\n| Field Name       | Type          | Description                                                                         |\n| ---------------- | ------------- | ----------------------------------------------------------------------------------- |\n| prisma           | Prisma Client |                                                                                     |\n| userId           | string        |                                                                                     |\n| secret           | string        | Secret use for accessToken generation                                               |\n| refreshSecret    | string?       | Secret use for refreshToken generation                                              |\n| accessTokenTime  | string        | Time validity for accessToken [Help for time format](https://github.com/vercel/ms)  |\n| refreshTokenTime | string        | Time validity for refreshToken [Help for time format](https://github.com/vercel/ms) |\n\n**Return**\n\n| Field Name   | Type   | Description |\n| ------------ | ------ | ----------- |\n| accessToken  | string |             |\n| refreshToken | string |             |\n\n### removeUserToken(prisma)(accessToken)\n\n**Options**\n| Field Name  | Type          | Description |\n| ----------- | ------------- | ----------- |\n| prisma      | Prisma Client |             |\n| accessToken | string        |             |\n\n**Return** void\n\n### removeAllUserTokens(prisma)(userId)\n\n**Options**\n| Field Name | Type          | Description |\n| ---------- | ------------- | ----------- |\n| prisma     | Prisma Client |             |\n| userId     | string        |             |\n\n**Return** void\n\n### refreshUserToken(prisma)(refreshToken, { secret, refreshSecret, accessTokenTime })\n\n**Options**\n| Field Name      | Type          | Description                                                                        |\n| --------------- | ------------- | ---------------------------------------------------------------------------------- |\n| prisma          | Prisma Client |                                                                                    |\n| refreshToken    | string        | Refresh token generated                                                            |\n| secret          | string        | Secret use for accessToken generation                                              |\n| refreshSecret   | string        | Secret use for refreshToken generation                                             |\n| accessTokenTime | string        | Time validity for accessToken [Help for time format](https://github.com/vercel/ms) |\n\n**Return**\n\n| Field Name   | Type   | Description |\n| ------------ | ------ | ----------- |\n| accessToken  | string |             |\n| refreshToken | string |             |\n\n### getAccessTokenFromRequest(req)\n\n**Options**\n| Field Name | Type            | Description |\n| ---------- | --------------- | ----------- |\n| req        | Fastify request |             |\n\n**Return** string\n\n## Config Array\n\nTo configure your public routes, you need to specify your url and your method. You can use some alias too :\n\n- Standard example : `{url: '/test/toto', method: 'GET'}`\n- Match url who start with test : `{url: '/test/*', method: 'GET'}`\n- Match all methods for this url : `{url: '/test/toto', method: '*'}`\n- Match url who contain dynamic variable in it : `{url: '/test/:var1/test', method: 'GET'}`\n\nYou can combine all this options of course ! `{url: '/test/:testvar/toto/*', method: '*'}`\n\n## Test\n\nTo test this package, you need to run a PostgresSQL server :\n\n```bash\n\ndocker-compose up -d\nchmod -R 777 docker\npnpm prisma migrate deploy\npnpm test\n```\n\n## Maintain\n\nThis package use [TSdx](https://github.com/jaredpalmer/tsdx). Please check documentation to update this package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqlaffont%2Ffastify-auth-prisma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqlaffont%2Ffastify-auth-prisma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqlaffont%2Ffastify-auth-prisma/lists"}