{"id":13796897,"url":"https://github.com/Camji55/nexus-plugin-jwt-auth","last_synced_at":"2025-05-13T00:31:19.756Z","repository":{"id":174064413,"uuid":"258635544","full_name":"Camji55/nexus-plugin-jwt-auth","owner":"Camji55","description":"Basic jsonwebtoken authentication plugin for The Nexus Framework","archived":true,"fork":false,"pushed_at":"2020-09-18T17:44:52.000Z","size":355,"stargazers_count":56,"open_issues_count":5,"forks_count":14,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2024-08-03T23:07:28.071Z","etag":null,"topics":["authentication","graphql","jsonwebtoken","jwt","jwt-token","nexus-plugin","nexusjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nexus-plugin-jwt-auth","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/Camji55.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2020-04-24T22:11:41.000Z","updated_at":"2024-08-03T23:07:29.721Z","dependencies_parsed_at":null,"dependency_job_id":"18d3353c-6a81-4d9f-abab-658541893a6f","html_url":"https://github.com/Camji55/nexus-plugin-jwt-auth","commit_stats":null,"previous_names":["camji55/nexus-plugin-jwt-auth"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Camji55%2Fnexus-plugin-jwt-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Camji55%2Fnexus-plugin-jwt-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Camji55%2Fnexus-plugin-jwt-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Camji55%2Fnexus-plugin-jwt-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Camji55","download_url":"https://codeload.github.com/Camji55/nexus-plugin-jwt-auth/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225159887,"owners_count":17430205,"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":["authentication","graphql","jsonwebtoken","jwt","jwt-token","nexus-plugin","nexusjs"],"created_at":"2024-08-03T23:01:17.646Z","updated_at":"2024-11-18T10:31:42.587Z","avatar_url":"https://github.com/Camji55.png","language":"TypeScript","funding_links":[],"categories":["🏗️ Plugins"],"sub_categories":["Authentication"],"readme":"![header](https://user-images.githubusercontent.com/2769158/80298536-2796b180-8742-11ea-81c4-fcbcca851083.png)\n\n## Contents\n\n- [Contents](#contents)\n- [Installation](#installation)\n- [Example Usage](#example-usage)\n  - [Setup](#setup)\n  - [Permissions](#permissions)\n  - [Stored Properties](#stored-properties)\n- [Use cookie instead of Authorization header](#use-cookie-instead-of-authorization-header)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\n```sh\nnpm install nexus-plugin-jwt-auth\n```\n\n## Example Usage\n\nFind full examples using both the built in permissions system or by leveragering [nexus-plugin-shield](https://github.com/lvauvillier/nexus-plugin-shield):\n\n- **Basic Permissions** - [examples/basic-permissions](https://github.com/Camji55/nexus-plugin-jwt-auth/tree/master/examples/basic-permissions)\n- **[Shield](https://github.com/lvauvillier/nexus-plugin-shield)** -  [examples/shield](https://github.com/Camji55/nexus-plugin-jwt-auth/tree/master/examples/shield)\n\n### Setup\n\n```typescript\n// app.ts\n\nimport { use } from 'nexus'\nimport { auth } from 'nexus-plugin-jwt-auth'\n\n// Enables the JWT Auth plugin without permissions\nuse(auth({\n  appSecret: \"\u003cYOUR SECRET\u003e\" // optional if using custom verify function\n}))\n```\n\nYou may now access the `token` object and it's properties on the Nexus `context`.\n\n### Permissions\n\nBasic permissions can be added too.\n\n```typescript\n// app.ts\n\nimport { use } from 'nexus'\nimport { auth } from 'nexus-plugin-jwt-auth'\n\n// Define the paths you'd like to protect\nconst protectedPaths = [\n    'Query.me',\n    'Query.filterPosts',\n    'Query.post',\n    'Mutation.createDraft',\n    'Mutation.deletePost',\n    'Mutation.publish'\n]\n\n// Enables the JWT Auth plugin with permissions\nuse(auth({\n  appSecret: \"\u003cYOUR SECRET\u003e\", // optional if using custom verify function\n  protectedPaths // optional\n}))\n```\n\n### Stored Properties\n\nYou can also access properties stored in the token.\n\n\u003e In this example I sign the token on signup or login then store the userId in the token to be accessed directly in a query or mutation to find the authed user.\n\n```typescript\n// Query.ts\n\nimport { schema } from 'nexus'\n\nschema.queryType({\n  definition(t) {\n    t.field('me', {\n      type: 'User',\n      async resolve(_root, _args, ctx) {\n        const user = await ctx.db.user.findOne({\n          where: {\n            id: ctx.token.userId // This is the token object passed through the context\n          }\n        })\n\n        if (!user) {\n          throw new Error('No such user exists')\n        }\n\n        return user\n      }\n    })\n  }\n})\n```\n\n## Use cookie instead of Authorization header\n\n```typescript\nimport { use, server } from \"nexus\"\nimport cookieParser from \"cookie-parser\" // Set esModuleInterop: true in tsconfig.json\n\n// Add the cookie-parser middleware to Express\nserver.express.use(cookieParser())\n\n// Enables the JWT Auth plugin with cookies\nuse(auth({\n  // ...\n  useCookie: true,\n  cookieName: \"token\"\n}))\n```\n\nDon't forget to set `credentials: true` in your GraphQL client or the cookie will not be sent to the server.\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## License\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FCamji55%2Fnexus-plugin-jwt-auth.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FCamji55%2Fnexus-plugin-jwt-auth?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCamji55%2Fnexus-plugin-jwt-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCamji55%2Fnexus-plugin-jwt-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCamji55%2Fnexus-plugin-jwt-auth/lists"}