{"library":"next-auth","title":"NextAuth.js","description":"NextAuth.js (version 4.24.14) provides comprehensive authentication solutions for Next.js applications, supporting a wide range of authentication providers including OAuth, email, and credentials. This package is currently in maintenance mode, with active feature development now taking place in Auth.js (v5) under the `@auth/nextjs` package. It receives critical bug fixes and security updates for its v4 branch.","language":"javascript","status":"maintenance","last_verified":"Sat Apr 18","install":{"commands":["npm install next-auth"],"cli":null},"imports":["import { AuthOptions } from 'next-auth'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import NextAuth, { type AuthOptions } from 'next-auth';\nimport GitHubProvider from 'next-auth/providers/github';\n\n// For production, ensure these are robustly set via environment variables.\n// Example using a database adapter (uncomment and install if needed):\n// import { MongoDBAdapter } from '@next-auth/mongodb-adapter';\n// import clientPromise from '../../../lib/mongodb'; // Your MongoDB connection logic\n\nexport const authOptions: AuthOptions = {\n  // Configure one or more authentication providers\n  providers: [\n    GitHubProvider({\n      clientId: process.env.GITHUB_ID ?? '',\n      clientSecret: process.env.GITHUB_SECRET ?? ''\n    })\n    // ...add more providers here\n  ],\n  // Optional: Add a database adapter if you want to persist user sessions\n  // adapter: MongoDBAdapter(clientPromise),\n  \n  // REQUIRED: A secret to sign and encrypt session tokens. \n  // Use `openssl rand -base64 32` to generate a strong one.\n  secret: process.env.NEXTAUTH_SECRET ?? '',\n\n  // Callbacks are essential for custom session data, redirects, etc.\n  // https://next-auth.js.org/configuration/callbacks\n  callbacks: {\n    async session({ session, token, user }) {\n      // Example: add user ID to session (useful for database-backed sessions)\n      if (token?.sub) {\n        session.user.id = token.sub; \n      }\n      return session;\n    }\n  },\n  // Enable debug messages in the console during development\n  debug: process.env.NODE_ENV === 'development'\n};\n\nexport default NextAuth(authOptions);","lang":"typescript","description":"This code sets up a basic NextAuth.js API route (`pages/api/auth/[...nextauth].ts`) using GitHub as an OAuth provider. It demonstrates provider configuration, the mandatory `secret` environment variable, and a simple session callback.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}