na

next-auth

Authentication for Next.js

Showing:

Popularity

Downloads/wk

87.7K

GitHub Stars

7.8K

Maintenance

Last Commit

2mos ago

Contributors

235

Package

Dependencies

12

License

ISC

Type Definitions

Built-In

Tree-Shakeable

No?

Reviews

Average Rating

4.4/511
Read All Reviews
soydavidpaucar
Abhishek635
rushabh10101

Top Feedback

5Highly Customizable
3Great Documentation
3Easy to Use

Readme


NextAuth.js

Authentication for Next.js

Open Source. Full Stack. Own Your Data.

Release Bundle Size Downloads Github Stars Github Stable Release Github Prelease

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.

Getting Started

npm install --save next-auth

The easiest way to continue getting started, is to follow the getting started section in our docs.

We also have a section of tutorials for those looking for more specific examples.

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

Features

Flexible and easy to use

  • Designed to work with any OAuth service, it supports OAuth 1.0, 1.0A and 2.0
  • Built-in support for many popular sign-in services
  • Supports email / passwordless authentication
  • Supports stateless authentication with any backend (Active Directory, LDAP, etc)
  • Supports both JSON Web Tokens and database sessions
  • Designed for Serverless but runs anywhere (AWS Lambda, Docker, Heroku, etc…)

Own your own data

NextAuth.js can be used with or without a database.

  • 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 MySQL, MariaDB, Postgres, Microsoft SQL Server, 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

  • Promotes the use of passwordless sign in mechanisms
  • Designed to be secure by default and encourage best practice for safeguarding user data
  • Uses Cross Site Request Forgery Tokens on POST routes (sign in, sign out)
  • Default cookie policy aims for the most restrictive policy appropriate for each cookie
  • When JSON Web Tokens are enabled, they are signed by default (JWS) with HS512
  • Use JWT encryption (JWE) by setting the option encryption: true (defaults to A256GCM)
  • Auto-generates symmetric signing and encryption keys for developer convenience
  • Features tab/window syncing and keepalive messages to support short lived sessions
  • Attempts to implement the latest guidance published by Open Web Application Security Project

Advanced options allow you to define your own routines to handle controlling what accounts are allowed to sign in, for encoding and decoding JSON Web Tokens and to set custom cookie security policies and session properties, so you can control who is able to sign in and how often sessions have to be re-validated.

TypeScript

NextAuth.js comes with built-in types. For more information and usage, check out the TypeScript section in the documentation.

The package at @types/next-auth is now deprecated.

Example

Add API Route

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

export default NextAuth({
  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,
})

Add React Component

import { useSession, signIn, signOut } from "next-auth/client"

export default function Component() {
  const [session, loading] = useSession()
  if (session) {
    return (
      <>
        Signed in as {session.user.email} <br />
        <button onClick={() => signOut()}>Sign out</button>
      </>
    )
  }
  return (
    <>
      Not signed in <br />
      <button onClick={() => signIn()}>Sign in</button>
    </>
  )
}

Acknowledgements

NextAuth.js is made possible thanks to all of its contributors.

Support

We're happy to announce we've recently created an OpenCollective for individuals and companies looking to contribute financially to the project!

Vercel Logo
Vercel

🥉 Bronze Financial Sponsor
☁️ Infrastructure Support
Prisma Logo
Prisma

🥉 Bronze Financial Sponsor
Checkly Logo
Checkly

☁️ Infrastructure Support

Contributing

We're open to all community contributions! If you'd like to contribute in any way, please first read our Contributing Guide.

License

ISC

Rate & Review

Great Documentation3
Easy to Use3
Performant0
Highly Customizable5
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
David PaucarQuito, Ecuador26 Ratings40 Reviews
I'm David, a full-time full-stack freelance developer 👨‍💻 working since 2017 🚀
2 months ago
Great Documentation
Easy to Use
Highly Customizable

By far perfect and quickly login options that I've implemented on my projects, so easy to create a login page with all options who programmers needs, I personally love this library to create custom logins with few options to signin in like google, github, facebook, and with so few code lines, it's incredible.


1
riginoommen
Abhishek24 Ratings36 Reviews
2 months ago
Highly Customizable

Quick and have good features for the login. It is designed in such a way that it is secure, confidential client and implements a server side authentication flow. creating custom logins is really become easy.


0
rushabh1010155 Ratings82 Reviews
5 months ago
Easy to Use

I have used next auth which in turns helped me to create the the feature which supports password less log-in mechanisms and also its main feature and is designed by default to be secure and help with user data. Also supports cross site request and provide essential privacy on post routes.


0
Nikolay KolevIrvine, CA, US75 Ratings0 Reviews
Full-Stack Cloud Architect
23 days ago
Alexander RussellSaskatoon, Saskatchewan68 Ratings8 Reviews
3 months ago
Easy to Use
Great Documentation
Highly Customizable

Tutorials

No tutorials found
Add a tutorial