{"id":13530423,"url":"https://github.com/ooade/next-apollo-auth","last_synced_at":"2025-04-13T05:05:23.480Z","repository":{"id":40945020,"uuid":"112606854","full_name":"ooade/next-apollo-auth","owner":"ooade","description":"Authentication Boilerplate with Next.js and Apollo GraphQL","archived":false,"fork":false,"pushed_at":"2025-03-28T10:27:27.000Z","size":1271,"stargazers_count":203,"open_issues_count":6,"forks_count":35,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-04-13T05:04:48.109Z","etag":null,"topics":["apollo","authentication","expressjs","graphql","nextjs"],"latest_commit_sha":null,"homepage":"https://next-auth-apollo.now.sh","language":"JavaScript","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/ooade.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":"2017-11-30T12:06:00.000Z","updated_at":"2025-04-05T05:45:25.000Z","dependencies_parsed_at":"2024-06-18T10:27:54.154Z","dependency_job_id":"3f134742-6e0c-4aef-8dba-588370cb3843","html_url":"https://github.com/ooade/next-apollo-auth","commit_stats":{"total_commits":77,"total_committers":5,"mean_commits":15.4,"dds":0.4415584415584416,"last_synced_commit":"26e5f0b38cff53c4586c9e15c8786baf5e70fa15"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ooade%2Fnext-apollo-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ooade%2Fnext-apollo-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ooade%2Fnext-apollo-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ooade%2Fnext-apollo-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ooade","download_url":"https://codeload.github.com/ooade/next-apollo-auth/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665748,"owners_count":21142123,"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":["apollo","authentication","expressjs","graphql","nextjs"],"created_at":"2024-08-01T07:00:49.625Z","updated_at":"2025-04-13T05:05:23.434Z","avatar_url":"https://github.com/ooade.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Auth Example with Next.js and Apollo\n\nThis example shows how to implement Authentication with Next.js and Apollo GraphQL.\n\n## Main Technologies Used\n\n* Apollo GraphQl\n* Express.js\n* Express Validator\n* Next.js\n* Passport.js\n* Passport-local-mongoose\n* Passport-github\n\n## Contents\n\n* [Project Structure](#project-structure)\n* [Mutations](#mutations)\n  * [Schema](#schema)\n  * [Resolvers](#resolvers)\n* [Models](#models)\n* [Deploy](#deploy)\n\n### Project Structure\n\n```md\n├── components\n│   └── forms\n│   ├── login.js\n│   └── signup.js\n├── lib\n│   ├── initApollo.js\n│   └── withData.js\n├── pages\n│   ├── index.js\n│   ├── login.js\n│   └── signup.js\n└── server\n├── data\n│   ├── resolvers.js\n│   └── schema.js\n├── models\n│   └── User.js\n├── services\n│   └── passport.js\n└── index.js\n```\n\n### Mutations\n\n#### Schema\n\nHere we have one `User`'s type with three fields (email, fullname and password), one `Query` type with a profile field just to keep GraphQL's mouth shut about having a Query type defined. We have two `Mutation` types (login, and signup).\n\n```ts\ntype User {\n\temail: String\n\tfullname: String\n\tpassword: String\n}\n\ntype Query {\n\tprofile: User\n}\n\ntype Mutation {\n\tcreateUser(email: String!, fullname: String, password: String!): User\n\tlogin(email: String!, password: String!): User\n}\n```\n\n#### Resolvers\n\nThe resolvers we care about here are `createUser` and `login`. They both take in `email` and `password` as arguments with `createUser` taking an extra `fullname` argument.\n\n```js\nMutation: {\n\t\tcreateUser(root, { email, fullname, password }, { login }) {\n\t\t\tconst user = new User({ email, fullname })\n\n\t\t\treturn new Promise((resolve, reject) =\u003e {\n\t\t\t\treturn User.register(user, password, err =\u003e {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\treject(err)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogin(user, () =\u003e resolve(user))\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t})\n\t\t},\n\t\tlogin(root, { email, password }, { login }) {\n\t\t\treturn new Promise((resolve, reject) =\u003e {\n\t\t\t\treturn User.authenticate()(email, password, (err, user) =\u003e {\n\t\t\t\t\t// user returns false if username / email incorrect\n\t\t\t\t\tif (user) {\n\t\t\t\t\t\tlogin(user, () =\u003e resolve(user))\n\t\t\t\t\t} else {\n\t\t\t\t\t\treject('Email / Password Incorrect')\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t})\n\t\t}\n\t}\n```\n\n### Models\n\nOops! We have only one model (User). It accepts email, validates the email with `express-validator`. Then we have a plugin to tell `passport-local-mongoose` to use our email field as the default `usernameField`.\n\n```js\nconst userSchema = new Schema({\n\temail: {\n\t\ttype: String,\n\t\tunique: true,\n\t\tlowercase: true,\n\t\ttrim: true,\n\t\tvalidate: {\n\t\t\tisAsync: true,\n\t\t\tvalidator: (v, cb) =\u003e\n\t\t\t\tcb(validator.isEmail(v), `${v} is not a valid email address`)\n\t\t},\n\t\trequired: 'Please Supply an email address'\n\t},\n\tfullname: String\n})\n\nuserSchema.plugin(passportLocalMongoose, {\n\tusernameField: 'email',\n\terrorMessages: {\n\t\tUserExistsError: 'Email Already Exists'\n\t}\n})\n```\n\n### Deploy\n\n[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/ooade/next-apollo-auth)\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fooade%2Fnext-apollo-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fooade%2Fnext-apollo-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fooade%2Fnext-apollo-auth/lists"}