Auth.js

  • Next.js is main framework, but starting to support svelte & express (started as next-auth becoming @auth/*)

  • Supports 4 auth methods:

    • OAuth - google, github, linkedin, etc

    • Magic Links - supports resend, sendgrid, etc

    • Credentials - username&password + external APIs

    • WebAuthn - Passkeys

  • Supports database adapters to store user data, including prisma, neon, sup abase, etc

  • Comes with default set of pages

Setup

npm install next-auth@beta

Need to set the AUTH_SECRET env variable

npx auth secret #generate a good secret	

auth.ts

import NextAuth from "next-auth"
 
export const { handlers, signIn, signOut, auth } = NextAuth({
  providers: [],
})

./app/api/auth/[...nextauth]/route.ts

./middleware.ts

Credentials

Usage

To use session in app router

app/admin/dashboard.tsx

app/admin/page.tsx

Last updated