Files
archived-next-auth/example/README.md
Iain Collins bf3c5fb273 Adding support for credentials based sign in
* Resolves #18 by providing an easy way to define a custom credentials based sign in end point and use it with NextAuth.

The NextAuth client explicitly supports this option and an new example in example/pages/credentials.js shows how to use it (it’s super easy to use and and you can pass any fields you like to it).

Note that this does not explicitly allow a localStrategy to be defined but provides the same ability to define a custom auth hook - allowing custom localStrategies would probably be a footgun and likely generate support requests (as it’s more complicated to implement) so I’m inclined to keep it simple for everyone.

* Resolves #20 by passing the req to email sign in method (useful for things like language and hostname detection).

* If you do not pass a sendSignInEmail() or signIn() functions (or set them to null) then the routes for these will not be created, so that they are easy to disable.
2018-02-18 00:09:15 +01:00

1.6 KiB

NextAuth Example

About NextAuth Example

This is an example of how to use the NextAuth module.

Getting Started

This project as is run the same way as any Next.js project.

To run it locally, just use:

nmp run dev

To run it it production mode, use:

npm build
npm start

Using NextAuth

NextAuth is included in this project here:

  • index.js

Pages

This example includes the following pages:

  • pages/index.js
  • pages/auth/index.js
  • pages/auth/error.js
  • pages/auth/check-email.js
  • pages/auth/callback.js

The file pages/auth/credentials.js provides an additional example of how to use a custom authentication handler defined in next-auth.functions.js.

Configuration

It also includes the following configuration files:

  • next-auth.config.js
  • next-auth.functions.js
  • next-auth.providers.js

An example .env file is provided in .env.example which you can copy over to use for simple configuration:

SERVER_URL=http://localhost:3000
MONGO_URI=mongodb://localhost:27017/my-database
FACEBOOK_ID=
FACEBOOK_SECRET=
GOOGLE_ID=
GOOGLE_SECRET=
TWITTER_KEY=
TWITTER_SECRET=
EMAIL_FROM=username@gmail.com
EMAIL_SERVER=smtp.gmail.com
EMAIL_PORT=465
EMAIL_USERNAME=username@gmail.com
EMAIL_PASSWORD=

If you don't specify a MONGO_URI it will use an in-memory data store for user and session data.

If you don't specify oAuth or SMTP email details you will not be able to log in.

For a more complete example with live demo see nextjs-starter.now.sh.