The Wayback Machine - https://web.archive.org/web/20200616210200/https://github.com/iaincollins/next-auth
Skip to content
Easy authentication for Next.js and Serverless
JavaScript CSS
Branch: main
Clone or download

Latest commit

iaincollins Update issue templates to point to documentation
Have been the asked some questions a few times (including via email).

Most of the time these reports have already been addressed.

Trying to nudge behaviour to check the example project and docs first.

Also want to understand where people couldn't find what they needed.

Removed pre-filled issue title as people were forgetting to change it.
1
Latest commit 0119622 Jun 16, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE Update issue templates to point to documentation Jun 16, 2020
src Added IdentityServer4 Jun 15, 2020
test Change all instances of "identifer" to "identifier" (#267) Jun 15, 2020
www fixed some small typo in models docs Jun 15, 2020
.gitignore Fix issue with docusaurus config on now.sh May 17, 2020
CODE_OF_CONDUCT.md Update documentation May 17, 2020
CONTRIBUTING.md Rename master branch to main Jun 13, 2020
LICENSE.txt Update documentation May 17, 2020
README.md Fix typo Jun 9, 2020
adapters.js Fix default exports in entrypoints May 25, 2020
babel.config.json Refactor Apple provider to genereate secret dynamically Jun 1, 2020
client.js Fix issues with database; make it easier to test May 25, 2020
index.js Add babel config for esmodule May 17, 2020
jwt.js Refactor JWT, Sessions and add allowSignin() method (#223) Jun 8, 2020
package-lock.json Refactoring naming strategy Jun 14, 2020
package.json Bump beta version to 78 Jun 15, 2020
postcss.config.js Add eslint with Standard JS and reformat code May 17, 2020
providers.js Fix default exports in entrypoints May 25, 2020

README.md

NextAuth.js

Overview

NextAuth.js is a complete open source authentication solution for Next.js applications.

It is designed from the ground up to support Next.js and Serverless.

Follow the examples to see how easy it is to use NextAuth.js for authentication.

Install: npm i next-auth

See next-auth.js.org for more information and documentation.

Features

Authentication

  • Designed to work with any OAuth service, it supports OAuth 1.0, 1.0A and 2.0
  • Built-in support for many popular OAuth sign-in services
  • Supports email / passwordless authentication
  • Supports both JSON Web Tokens and database sessions

Own your own data

  • An open source solution that allows you to keep control of your data
  • Supports Bring Your Own Database (BYOD) and can be used with any database
  • Built-in support for for MySQL, MariaDB, Postgres, MongoDB and SQLite
  • Works great with databases from popular hosting providers
  • Can also be used without a database (e.g. OAuth + JWT)

Secure by default

Security focused features include CSRF protection, use of signed cookies, cookie prefixes, secure cookies, HTTP only, host only and secure only cookies and promoting passwordless sign-in.

Example

Add API Route

import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'

const options = {
  site: 'https://example.com'
  providers: [
    // OAuth authentication providers
    Providers.Apple({
      clientId: process.env.APPLE_ID,
      clientSecret: process.env.APPLE_SECRET
    }),
    Providers.Google({
      clientId: process.env.GOOGLE_ID,
      clientSecret: process.env.GOOGLE_SECRET
    }),
    // Sign in with passwordless email link
    Providers.Email({
      server: process.env.MAIL_SERVER,
      from: '<no-reply@example.com>'
    }),
  ],
  // SQL or MongoDB database (or leave empty)
  database: process.env.DATABASE_URL
}

export default (req, res) => NextAuth(req, res, options)

Add React Component

import React from 'react'
import { 
  useSession, 
  signin, 
  signout 
} from 'next-auth/client'

export default () => {
  const [ session, loading ] = useSession()

  return <p>
    {!session && <>
      Not signed in <br/>
      <button onClick={signin}>Sign in</button>
    </>}
    {session && <>
      Signed in as {session.user.email} <br/>
      <button onClick={signout}>Sign out</button>
    </>}
  </p>
}

Acknowledgement

NextAuth.js 2.0 is possible thanks to its contributors.

Getting started

Follow the examples to get started.

You can’t perform that action at this time.