{"id":22733200,"url":"https://github.com/fantasywind/graphql-auth-keeper","last_synced_at":"2025-04-14T01:53:49.123Z","repository":{"id":57253348,"uuid":"131476323","full_name":"fantasywind/graphql-auth-keeper","owner":"fantasywind","description":"Endpoint Auth Keeper for GraphQL Application","archived":false,"fork":false,"pushed_at":"2018-11-02T06:52:57.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T01:53:44.555Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/fantasywind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-29T07:57:19.000Z","updated_at":"2023-03-08T16:07:47.000Z","dependencies_parsed_at":"2022-08-31T22:11:54.705Z","dependency_job_id":null,"html_url":"https://github.com/fantasywind/graphql-auth-keeper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasywind%2Fgraphql-auth-keeper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasywind%2Fgraphql-auth-keeper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasywind%2Fgraphql-auth-keeper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fantasywind%2Fgraphql-auth-keeper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fantasywind","download_url":"https://codeload.github.com/fantasywind/graphql-auth-keeper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809032,"owners_count":21164895,"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":[],"created_at":"2024-12-10T20:13:16.330Z","updated_at":"2025-04-14T01:53:49.097Z","avatar_url":"https://github.com/fantasywind.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graphql-auth-keeper\nEndpoint Auth Keeper for GraphQL Application\n\n## Apollo Server Support\n```javascript\nconst authKeeper = new GraphQLAuthKeeper({\n  secret: 'JWT_SECRET',\n});\n\nconst server = new ApolloServer(authKeeper.apolloServerOptions({ schema }));\n```\n\n## Example\n\n### Member Action Check\n```javascript\nimport {\n  GraphQLInt,\n  GraphQLNonNull,\n  GraphQLString,\n} from 'graphql';\nimport Koa from 'koa';\nimport Router from 'koa-router';\nimport koaBody from 'koa-bodyparser';\nimport { graphqlKoa, graphiqlKoa } from 'apollo-server-koa';\nimport GraphQLAuthKeeper, { authKeeper } from 'graphql-auth-keeper';\nimport { SubscriptionServer } from 'subscriptions-transport-ws';\nimport { db } from './db';\nimport { memberType } from './memberType';\n\nconst CREATE_MEMBER = {\n  name: 'Create Member',\n  code: 1,\n};\n\nconst meQuery = {\n  type: memberType,\n  resolve: authKeeper({\n    onFailed: new Error('Auth Failed'),\n    onlineData: true,\n  })(member =\u003e member),\n};\n\nconst createMemberMutation = {\n  type: GraphQLInt,\n  args: {\n    account: {\n      type: new GraphQLNonNull(GraphQLString),\n    },\n    password: {\n      type: new GraphQLNonNull(GraphQLString),\n    },\n  },\n  resolve: authKeeper({\n    onFailed: new Error('Auth Failed'),\n    actions: CREATE_MEMBER,    \n  })(async (member, {\n    account,\n    password,\n  }) =\u003e {\n    const createdMember = await db.models.Member.create({\n      account,\n      password,\n      CreatorId: member.id,\n    });\n\n    return createdMember.id;\n  }),\n};\n\nconst schema = new GraphQLSchema({\n  query: new GraphQLObjectType({\n    name: 'Query',\n    fields: {\n      me: meQuery,\n    },\n  }),\n  mutation: new GraphQLObjectType({\n    name: 'Mutation',\n    fields: {\n      createMember: createMemberMutation,\n    },\n  }),\n});\n\nconst app = new Koa();\nconst router = new Router();\nconst authKeeper = new GraphQLAuthKeeper({\n  syncFn: payload =\u003e db.models.Member.findOne({\n    where: {\n      id: payload.id,\n    },\n  }),\n  secret: 'JWT_SECRET',\n});\n\nrouter.post('/graphql', koaBody(), graphqlKoa(authKeeper.middleware({\n  schema,\n})));\n\napp.use(router.routes());\napp.use(router.allowedMethods());\n\nconst server = createServer(app.callback());\n\nSubscriptionServer.create({\n  schema,\n  subscribe,\n  execute,\n  onOperation: authKeeper.subscriptionOperationMiddleware(),\n}, {\n  server,\n  path: '/graphql',\n});\n\nserver.listen(3000);\n```\n\n## Keeper Options\n\n- secret(string)[required]: JWT Secret\n- syncFn(Function): Should return live data by payload info\n\n## Route Options\n\n- logined(boolean): Require valid JWT token or not\n- actions(Action | Array\u003cAction\u003e): Required actions\n- onlineData(boolean): Should return online (syncd) data on resolve payload\n- onFailed(Error | Function | any): If Error given will throw it. Function will execute and return it result or return data directly.\n- orMode(boolean): The actions should be match all or partial.\n\n## Context added by authKeeper\n\n- jwtPayload(any): JWT payload from token\n- authPayload(any): JWT payload from token, if syncFn set, the result will overwrite this value\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffantasywind%2Fgraphql-auth-keeper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffantasywind%2Fgraphql-auth-keeper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffantasywind%2Fgraphql-auth-keeper/lists"}