All Projects β†’ ooade β†’ Next Apollo Auth

ooade / Next Apollo Auth

Authentication Boilerplate with Next.js and Apollo GraphQL

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Next Apollo Auth

Pizzaql
πŸ• Modern OSS Order Management System for Pizza Restaurants
Stars: ✭ 631 (+296.86%)
Mutual labels:  graphql, apollo, nextjs, authentication
Next Advanced Apollo Starter
Advanced, but minimalistic Next.js pre-configured starter with focus on DX
Stars: ✭ 131 (-17.61%)
Mutual labels:  graphql, apollo, nextjs, authentication
Next Apollo Example
Next & Apollo Example
Stars: ✭ 413 (+159.75%)
Mutual labels:  graphql, apollo, nextjs
Hackernews React Graphql
Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
Stars: ✭ 4,242 (+2567.92%)
Mutual labels:  graphql, apollo, nextjs
Meteor Apollo Accounts
Meteor accounts in GraphQL
Stars: ✭ 145 (-8.81%)
Mutual labels:  graphql, apollo, authentication
Babel Plugin Import Graphql
Enables import syntax for .graphql and .gql files
Stars: ✭ 284 (+78.62%)
Mutual labels:  graphql, apollo, nextjs
Apollo Upload Examples
A full stack demo of file uploads via GraphQL mutations using Apollo Server and apollo-upload-client.
Stars: ✭ 358 (+125.16%)
Mutual labels:  graphql, apollo, nextjs
Brian Lovin Next
My personal site
Stars: ✭ 522 (+228.3%)
Mutual labels:  graphql, apollo, nextjs
Example Storefront
Example Storefront is Reaction Commerce’s headless ecommerce storefront - Next.js, GraphQL, React. Built using Apollo Client and the commerce-focused React UI components provided in the Storefront Component Library (reactioncommerce/reaction-component-library). It connects with Reaction backend with the GraphQL API.
Stars: ✭ 471 (+196.23%)
Mutual labels:  graphql, apollo, nextjs
Crypto Grommet
Crypto and equities app
Stars: ✭ 39 (-75.47%)
Mutual labels:  graphql, apollo, nextjs
Naperg
Fullstack Boilerplate GraphQL. Made with React & Prisma + authentication & roles
Stars: ✭ 661 (+315.72%)
Mutual labels:  apollo, expressjs, authentication
Next Graphql Blog
πŸ–Š A Blog including a server and a client. Server is built with Node, Express & a customized GraphQL-yoga server. Client is built with React, Next js & Apollo client.
Stars: ✭ 152 (-4.4%)
Mutual labels:  graphql, apollo, nextjs
Next Ecommerce
⚑️ Quantum Ecommerce. Made with Next.js | GraphQL | Apollo Server | Apollo Client | SSR
Stars: ✭ 186 (+16.98%)
Mutual labels:  graphql, apollo, nextjs
Next React Graphql Apollo Hooks
React, Apollo, Next.js, GraphQL, Node.js, TypeScript high performance boilerplate with React hooks GraphQL implementation and automatic static type generation
Stars: ✭ 186 (+16.98%)
Mutual labels:  graphql, apollo, nextjs
Ran
⚑ RAN! React . GraphQL . Next.js Toolkit ⚑ - SEO-Ready, Production-Ready, SSR, Hot-Reload, CSS-in-JS, Caching, CLI commands and more...
Stars: ✭ 2,128 (+1238.36%)
Mutual labels:  graphql, apollo, nextjs
Apollo Server Vercel
⚫ Production-ready Node.js GraphQL server for Vercel Serverless Functions
Stars: ✭ 69 (-56.6%)
Mutual labels:  graphql, apollo, nextjs
Next React Graphql Apollo boostrap
React + GraphQL + Next.js project architecture that I play with right now
Stars: ✭ 59 (-62.89%)
Mutual labels:  graphql, apollo, nextjs
Nextjs Headless Wordpress
πŸ”₯ Nextjs Headless WordPress
Stars: ✭ 110 (-30.82%)
Mutual labels:  graphql, nextjs, authentication
Notion Clone
Stars: ✭ 2,048 (+1188.05%)
Mutual labels:  nextjs, expressjs
Giraffeql
πŸ¦’ Developer tool to visualize relational databases and export schemas for GraphQL API's.
Stars: ✭ 128 (-19.5%)
Mutual labels:  graphql, nextjs

Auth Example with Next.js and Apollo

This example shows how to implement Authentication with Next.js and Apollo GraphQL.

Main Technologies Used

  • Apollo GraphQl
  • Express.js
  • Express Validator
  • Next.js
  • Passport.js
  • Passport-local-mongoose
  • Passport-github

Contents

Project Structure

β”œβ”€β”€ components
β”‚   └── forms
β”‚   β”œβ”€β”€ login.js
β”‚   └── signup.js
β”œβ”€β”€ lib
β”‚   β”œβ”€β”€ initApollo.js
β”‚   └── withData.js
β”œβ”€β”€ pages
β”‚   β”œβ”€β”€ index.js
β”‚   β”œβ”€β”€ login.js
β”‚   └── signup.js
└── server
β”œβ”€β”€ data
β”‚   β”œβ”€β”€ resolvers.js
β”‚   └── schema.js
β”œβ”€β”€ models
β”‚   └── User.js
β”œβ”€β”€ services
β”‚   └── passport.js
└── index.js

Mutations

Schema

Here 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).

type User {
	email: String
	fullname: String
	password: String
}

type Query {
	profile: User
}

type Mutation {
	createUser(email: String!, fullname: String, password: String!): User
	login(email: String!, password: String!): User
}

Resolvers

The 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.

Mutation: {
		createUser(root, { email, fullname, password }, { login }) {
			const user = new User({ email, fullname })

			return new Promise((resolve, reject) => {
				return User.register(user, password, err => {
					if (err) {
						reject(err)
					} else {
						login(user, () => resolve(user))
					}
				})
			})
		},
		login(root, { email, password }, { login }) {
			return new Promise((resolve, reject) => {
				return User.authenticate()(email, password, (err, user) => {
					// user returns false if username / email incorrect
					if (user) {
						login(user, () => resolve(user))
					} else {
						reject('Email / Password Incorrect')
					}
				})
			})
		}
	}

Models

Oops! 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.

const userSchema = new Schema({
	email: {
		type: String,
		unique: true,
		lowercase: true,
		trim: true,
		validate: {
			isAsync: true,
			validator: (v, cb) =>
				cb(validator.isEmail(v), `${v} is not a valid email address`)
		},
		required: 'Please Supply an email address'
	},
	fullname: String
})

userSchema.plugin(passportLocalMongoose, {
	usernameField: 'email',
	errorMessages: {
		UserExistsError: 'Email Already Exists'
	}
})

Deploy

Deploy to now

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].