Installations
npm install next-auth
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
20.8.0
NPM Version
10.1.0
Score
62.9
Supply Chain
83.8
Quality
93.4
Maintenance
50
Vulnerability
92.1
License
Releases
@auth/azure-tables-adapter@1.7.4
Published on 16 Nov 2024
@auth/d1-adapter@1.7.4
Published on 16 Nov 2024
@auth/dgraph-adapter@2.7.4
Published on 16 Nov 2024
@auth/drizzle-adapter@1.7.4
Published on 16 Nov 2024
@auth/dynamodb-adapter@2.7.4
Published on 16 Nov 2024
@auth/edgedb-adapter@1.7.4
Published on 16 Nov 2024
Contributors
Languages
TypeScript (93.33%)
JavaScript (2.74%)
CSS (1.35%)
Shell (0.96%)
Svelte (0.96%)
PLpgSQL (0.26%)
Pug (0.25%)
Dockerfile (0.12%)
HTML (0.04%)
Developer
Download Statistics
Total Downloads
87,497,291
Last Day
104,891
Last Week
937,239
Last Month
4,766,735
Last Year
48,027,867
GitHub Statistics
25,365 Stars
3,801 Commits
3,588 Forks
110 Watching
69 Branches
853 Contributors
Bundle Size
283.91 kB
Minified
82.78 kB
Minified + Gzipped
Package Meta Information
Latest Version
4.24.11
Package Id
next-auth@4.24.11
Unpacked Size
808.25 kB
Size
180.37 kB
File Count
486
NPM Version
10.1.0
Node Version
20.8.0
Publised On
06 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
87,497,291
Last day
-51%
104,891
Compared to previous day
Last week
-19%
937,239
Compared to previous week
Last month
2.9%
4,766,735
Compared to previous month
Last year
83.9%
48,027,867
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
5
Dev Dependencies
39
NextAuth.js
Authentication for Next.js
Open Source. Full Stack. Own Your Data.
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.
This is a monorepo containing the following packages / projects:
- The primary
next-auth
package - A development test application
- All
@next-auth/*-adapter
packages - The documentation site
Getting Started
npm install 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 practices for safeguarding user data
- Uses Cross-Site Request Forgery (CSRF) 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 encrypted by default (JWE) with A256GCM
- Auto-generates symmetric signing and encryption keys for developer convenience
- Features tab/window syncing and session polling 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.
Example
Add API Route
1// pages/api/auth/[...nextauth].js 2import NextAuth from "next-auth" 3import AppleProvider from "next-auth/providers/apple" 4import GoogleProvider from "next-auth/providers/google" 5import EmailProvider from "next-auth/providers/email" 6 7export default NextAuth({ 8 secret: process.env.SECRET, 9 providers: [ 10 // OAuth authentication providers 11 AppleProvider({ 12 clientId: process.env.APPLE_ID, 13 clientSecret: process.env.APPLE_SECRET, 14 }), 15 GoogleProvider({ 16 clientId: process.env.GOOGLE_ID, 17 clientSecret: process.env.GOOGLE_SECRET, 18 }), 19 // Sign in with passwordless email link 20 EmailProvider({ 21 server: process.env.MAIL_SERVER, 22 from: "<no-reply@example.com>", 23 }), 24 ], 25})
Add React Hook
The useSession()
React Hook in the NextAuth.js client is the easiest way to check if someone is signed in.
1import { useSession, signIn, signOut } from "next-auth/react" 2 3export default function Component() { 4 const { data: session } = useSession() 5 if (session) { 6 return ( 7 <> 8 Signed in as {session.user.email} <br /> 9 <button onClick={() => signOut()}>Sign out</button> 10 </> 11 ) 12 } 13 return ( 14 <> 15 Not signed in <br /> 16 <button onClick={() => signIn()}>Sign in</button> 17 </> 18 ) 19}
Share/configure session state
Use the <SessionProvider>
to allow instances of useSession()
to share the session object across components. It also takes care of keeping the session updated and synced between tabs/windows.
1import { SessionProvider } from "next-auth/react" 2 3export default function App({ 4 Component, 5 pageProps: { session, ...pageProps }, 6}) { 7 return ( 8 <SessionProvider session={session}> 9 <Component {...pageProps} /> 10 </SessionProvider> 11 ) 12}
Security
If you think you have found a vulnerability (or not sure) in NextAuth.js or any of the related packages (i.e. Adapters), we ask you to have a read of our Security Policy to reach out responsibly. Please do not open Pull Requests/Issues/Discussions before consulting with us.
Acknowledgments
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!
Clerk
💵
|
Auth0
💵
|
FusionAuth
💵
|
Stytch
💵
|
Prisma
💵
|
Neon
💵
|
Beyond Identity
💵
|
Lowdefy
💵
|
Descope
💵
|
Badass Courses
💵
|
Encore
💵
|
Sent.dm
💵
|
Arcjet
💵
|
Route4Me
💵
|
Netlight
☁️
|
Checkly
☁️
|
superblog
☁️
|
Vercel
☁️
|
- 💵 Financial Sponsor
- ☁️ 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
Stable Version
Stable Version
4.24.11
CRITICAL
2
9.1/10
Summary
NextAuth.js before 4.10.3 and 3.29.10 sending verification requests (magic link) to unwanted emails
Affected Versions
< 3.29.10
Patched Versions
3.29.10
9.1/10
Summary
NextAuth.js before 4.10.3 and 3.29.10 sending verification requests (magic link) to unwanted emails
Affected Versions
>= 4.0.0, < 4.10.3
Patched Versions
4.10.3
HIGH
5
8.1/10
Summary
Missing proper state, nonce and PKCE checks for OAuth authentication
Affected Versions
< 4.20.1
Patched Versions
4.20.1
7.1/10
Summary
Improper handling of email input
Affected Versions
>= 4.0.0, < 4.9.0
Patched Versions
4.9.0
7.1/10
Summary
Improper handling of email input
Affected Versions
< 3.29.8
Patched Versions
3.29.8
7.5/10
Summary
Improper Handling of `callbackUrl` parameter in next-auth
Affected Versions
>= 4.0.0, < 4.5.0
Patched Versions
4.5.0
7.5/10
Summary
Improper Handling of `callbackUrl` parameter in next-auth
Affected Versions
< 3.29.5
Patched Versions
3.29.5
MODERATE
5
5.3/10
Summary
Possible user mocking that bypasses basic authentication
Affected Versions
< 4.24.5
Patched Versions
4.24.5
6.1/10
Summary
URL Redirection to Untrusted Site ('Open Redirect') in next-auth
Affected Versions
>= 4.0.0, < 4.3.3
Patched Versions
4.3.3
6.1/10
Summary
URL Redirection to Untrusted Site ('Open Redirect') in next-auth
Affected Versions
< 3.29.3
Patched Versions
3.29.3
6.1/10
Summary
NextAuth.js default redirect callback vulnerable to open redirects
Affected Versions
>= 4.0.0, < 4.3.2
Patched Versions
4.3.2
6.1/10
Summary
NextAuth.js default redirect callback vulnerable to open redirects
Affected Versions
< 3.29.2
Patched Versions
3.29.2
LOW
3
3.3/10
Summary
next-auth before v4.10.2 and v3.29.9 leaks excessive information into log
Affected Versions
>= 4.0.0, < 4.10.2
Patched Versions
4.10.2
3.3/10
Summary
next-auth before v4.10.2 and v3.29.9 leaks excessive information into log
Affected Versions
< 3.29.9
Patched Versions
3.29.9
0/10
Summary
Token verification bug in next-auth
Affected Versions
< 3.3.0
Patched Versions
3.3.0
Reason
no dangerous workflow patterns detected
Reason
30 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/nextauthjs/.github/SECURITY.md:1
- Info: Found linked content: github.com/nextauthjs/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/nextauthjs/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/nextauthjs/.github/SECURITY.md:1
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 15 commits out of 22 are checked with a SAST tool
Reason
Found 15/26 approved changesets -- score normalized to 5
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: topLevel 'checks' permission set to 'write': .github/workflows/broken-link-checker.yml:9
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: no topLevel permission defined: .github/workflows/pr-labeler.yml:1
- Warn: no topLevel permission defined: .github/workflows/sync-examples.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/broken-link-checker.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/broken-link-checker.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/broken-link-checker.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/broken-link-checker.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/broken-link-checker.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/broken-link-checker.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr-labeler.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/pr-labeler.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:65: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:69: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:71: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:122: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:128: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:143: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:149: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:151: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:172: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:174: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:176: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:195: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:211: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:213: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:215: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sync-examples.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/sync-examples.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/sync-examples.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/sync-examples.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/triage.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/nextauthjs/next-auth/triage.yml/main?enable=pin
- Warn: containerImage not pinned by hash: apps/examples/nextjs/Dockerfile:2
- Warn: containerImage not pinned by hash: apps/examples/nextjs/Dockerfile:5
- Warn: containerImage not pinned by hash: apps/examples/nextjs/Dockerfile:15
- Warn: containerImage not pinned by hash: apps/examples/nextjs/Dockerfile:28
- Info: 0 out of 16 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 9 third-party GitHubAction dependencies pinned
- Info: 0 out of 4 containerImage dependencies pinned
Reason
53 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-6g33-8w2q-4hxv
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-3787-6prv-h9w3
- Warn: Project is vulnerable to: GHSA-9qxr-qj54-h672
- Warn: Project is vulnerable to: GHSA-m4v8-wqvr-p9f7
- Warn: Project is vulnerable to: GHSA-mgfv-m47x-4wqp
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-g77x-44xx-532m
- Warn: Project is vulnerable to: GHSA-gp8f-8m3g-qvj9
- Warn: Project is vulnerable to: GHSA-7gfc-8cq8-jh5f
- Warn: Project is vulnerable to: GHSA-2rwj-7xq8-4gx4
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
- Warn: Project is vulnerable to: GHSA-cchq-frgv-rjh5
- Warn: Project is vulnerable to: GHSA-g644-9gfx-q4q4
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx
- Warn: Project is vulnerable to: GHSA-mh2x-fcqh-fmqv
- Warn: Project is vulnerable to: GHSA-rjjv-87mx-6x3h
- Warn: Project is vulnerable to: GHSA-8266-84wp-wv5c
- Warn: Project is vulnerable to: GHSA-m5vv-6r4h-3vj9
- Warn: Project is vulnerable to: GHSA-f6v4-cf5j-vf3w
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-hhhv-q57g-882q
- Warn: Project is vulnerable to: GHSA-8cf7-32gw-wr33
- Warn: Project is vulnerable to: GHSA-hjrf-2m68-5959
- Warn: Project is vulnerable to: GHSA-qwph-4952-7xr6
- Warn: Project is vulnerable to: GHSA-3wc5-fcw2-2329
- Warn: Project is vulnerable to: GHSA-64fm-8hw2-v72w
- Warn: Project is vulnerable to: GHSA-cvr6-37gx-v8wc
- Warn: Project is vulnerable to: GHSA-f98w-7cxr-ff2h
- Warn: Project is vulnerable to: GHSA-pmh2-wpjm-fj45
- Warn: Project is vulnerable to: GHSA-9h6g-pr28-7cqp
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-3965-hpx2-q597
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-g3ch-rx76-35fx
Score
5.6
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More