NE

Next Auth

next-auth

Authentication for Next.js

Authentication
react
nodejs
oauth
jwt
oauth2
authentication
nextjs
csrf
oidc
nextauth
Stars
28k
Weekly
4.4M
Open issues
601
Bundle
~25 kB

Installation

npm install next-auth

Code example

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

export function Example() {
  const { data: session } = useSession();

  if (session) {
    return (
      <button type="button" onClick={() => signOut()}>
        Sign out {session.user?.email}
      </button>
    );
  }

  return (
    <button type="button" onClick={() => signIn()}>
      Sign in
    </button>
  );
}

Pros & cons

Pros

  • Actively maintained by Iain Collins
  • 4.4M weekly downloads. Battle tested
  • First-class TypeScript definitions
  • ISC licensed

Considerations

  • Adds roughly ~25 kB to your bundle
  • Not supported in React Native
  • 601 open issues on GitHub

FAQs

Alternatives & similar libraries