{"_id":"@api-buddy/auth-nextauth","_rev":"2-4370ba58f7a45bb32ebb4cc052a55986","name":"@api-buddy/auth-nextauth","dist-tags":{"latest":"3.0.0"},"versions":{"2.0.0":{"name":"@api-buddy/auth-nextauth","version":"2.0.0","_id":"@api-buddy/auth-nextauth@2.0.0","maintainers":[{"name":"iamtomhanks","email":"brechanson@gmail.com"}],"homepage":"https://github.com/api-buddy/api-buddy#readme","bugs":{"url":"https://github.com/api-buddy/api-buddy/issues"},"bin":{"api-buddy-nextauth":"cli.cjs"},"dist":{"shasum":"39fbedd1b5459fbda01287b528312adb7f240535","tarball":"https://registry.npmjs.org/@api-buddy/auth-nextauth/-/auth-nextauth-2.0.0.tgz","fileCount":25,"integrity":"sha512-eFzJaf1Rjv84hcZwAOK+X6ml7coU9m+A3X8bIFxE7Ov4aD/+n8TLrmZxQ2HZ3CKPtr+gkTnRSFY1ClMlG/ylnQ==","signatures":[{"sig":"MEQCIBJ5rpKUUT98BPVzMJDG/Vl6I7utOFcwRKJvRan2FKqLAiApOIY2/2/fgEhIzgiqOVaTc21m7VNobWR0jiIebI73bg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23260},"main":"dist/index.js","_from":"file:api-buddy-auth-nextauth-2.0.0.tgz","types":"dist/index.d.ts","scripts":{"dev":"tsup --watch","lint":"eslint src --ext .ts,.tsx","test":"jest","build":"pnpm clean && tsup","clean":"rimraf dist","format":"prettier --write \"src/**/*.{ts,tsx}\"","prebuild":"node -e \"const { execSync } = require('child_process'); const path = require('path'); const fs = require('fs'); let root = process.cwd(); while (root !== '/' && !fs.existsSync(path.join(root, 'pnpm-workspace.yaml'))) { root = path.dirname(root); } if (root === '/') { console.error('❌ Could not find project root directory'); process.exit(1); } require(path.join(root, 'scripts/ensure-tsup-config.js'));\"","type-check":"tsc --noEmit"},"_npmUser":{"name":"iamtomhanks","email":"brechanson@gmail.com"},"_resolved":"/private/var/folders/w3/00m0j5k95zjfx4vwz3csj_vc0000gn/T/8a1e7b48f49ae1a9244d78d0dd16c55c/api-buddy-auth-nextauth-2.0.0.tgz","_integrity":"sha512-eFzJaf1Rjv84hcZwAOK+X6ml7coU9m+A3X8bIFxE7Ov4aD/+n8TLrmZxQ2HZ3CKPtr+gkTnRSFY1ClMlG/ylnQ==","repository":{"url":"git+https://github.com/api-buddy/api-buddy.git","type":"git","directory":"packages/auth/nextauth"},"_npmVersion":"9.8.1","description":"API Buddy integration for NextAuth.js (Auth.js)","directories":{},"_nodeVersion":"18.18.0","dependencies":{"@api-buddy/plugin-core":"2.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","rimraf":"^5.0.5","typescript":"^5.0.0","@types/node":"^20.0.0","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","@api-buddy/tsup-config":"2.0.0"},"peerDependencies":{"next":">=14.0.0","react":">=18.0.0","next-auth":"^4.24.5"},"_npmOperationalInternal":{"tmp":"tmp/auth-nextauth_2.0.0_1750112549466_0.1116829178961789","host":"s3://npm-registry-packages-npm-production"}},"3.0.0":{"name":"@api-buddy/auth-nextauth","version":"3.0.0","description":"API Buddy integration for NextAuth.js (Auth.js)","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/api-buddy/api-buddy.git","directory":"packages/auth/nextauth"},"peerDependencies":{"react":">=18.0.0","next":">=14.0.0","next-auth":"^4.24.5"},"dependencies":{"@api-buddy/plugin-core":"3.0.0"},"devDependencies":{"@types/node":"^20.0.0","@types/react":"^18.0.0","@types/react-dom":"^18.0.0","tsup":"^8.0.0","typescript":"^5.0.0","rimraf":"^5.0.5","@api-buddy/tsup-config":"3.0.0"},"bin":{"api-buddy-nextauth":"cli.cjs"},"publishConfig":{"access":"public"},"scripts":{"build":"pnpm clean && tsup","dev":"tsup --watch","clean":"rimraf dist","test":"jest","lint":"eslint src --ext .ts,.tsx","type-check":"tsc --noEmit","format":"prettier --write \"src/**/*.{ts,tsx}\"","prebuild":"node -e \"const { execSync } = require('child_process'); const path = require('path'); const fs = require('fs'); let root = process.cwd(); while (root !== '/' && !fs.existsSync(path.join(root, 'pnpm-workspace.yaml'))) { root = path.dirname(root); } if (root === '/') { console.error('❌ Could not find project root directory'); process.exit(1); } require(path.join(root, 'scripts/ensure-tsup-config.js'));\""},"bugs":{"url":"https://github.com/api-buddy/api-buddy/issues"},"homepage":"https://github.com/api-buddy/api-buddy#readme","_id":"@api-buddy/auth-nextauth@3.0.0","_integrity":"sha512-xBn4eRlUMMr5BQkAD8RV1Zdq40iNXtjewlrR/640cCynC2XBY32iUMnxx6XSM871BM373Te667D3+zdviN6fTA==","_resolved":"/private/var/folders/w3/00m0j5k95zjfx4vwz3csj_vc0000gn/T/67b1fe3df3049edc27a8ff4de158e505/api-buddy-auth-nextauth-3.0.0.tgz","_from":"file:api-buddy-auth-nextauth-3.0.0.tgz","_nodeVersion":"18.18.0","_npmVersion":"9.8.1","dist":{"integrity":"sha512-xBn4eRlUMMr5BQkAD8RV1Zdq40iNXtjewlrR/640cCynC2XBY32iUMnxx6XSM871BM373Te667D3+zdviN6fTA==","shasum":"14b47bccd96a81f1e40a163789441b82da0da981","tarball":"https://registry.npmjs.org/@api-buddy/auth-nextauth/-/auth-nextauth-3.0.0.tgz","fileCount":25,"unpackedSize":23260,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDnCiJTtk5dvy5FlUn0XxkMgSBKQIhBTFrESV26/GmYJAIhAKA/zWL/JpebaE/Mkse6W2u32bVKIDsk0Gbnc6aoIkKB"}]},"_npmUser":{"name":"iamtomhanks","email":"brechanson@gmail.com","actor":{"name":"iamtomhanks","email":"brechanson@gmail.com","type":"user"}},"directories":{},"maintainers":[{"name":"iamtomhanks","email":"brechanson@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/auth-nextauth_3.0.0_1751386845330_0.16226036511801523"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-16T22:22:29.349Z","modified":"2025-07-01T16:20:45.700Z","2.0.0":"2025-06-16T22:22:29.701Z","3.0.0":"2025-07-01T16:20:45.516Z"},"bugs":{"url":"https://github.com/api-buddy/api-buddy/issues"},"homepage":"https://github.com/api-buddy/api-buddy#readme","repository":{"type":"git","url":"git+https://github.com/api-buddy/api-buddy.git","directory":"packages/auth/nextauth"},"description":"API Buddy integration for NextAuth.js (Auth.js)","maintainers":[{"name":"iamtomhanks","email":"brechanson@gmail.com"}],"readme":"# @api-buddy/nextauth\r\n\r\nAPI Buddy integration for NextAuth.js (Auth.js) - A complete authentication solution for Next.js applications.\r\n\r\n## Features\r\n\r\n- Easy setup with a single command\r\n- TypeScript support out of the box\r\n- Built-in session management\r\n- Support for multiple authentication providers\r\n- Secure JWT and database session strategies\r\n- Middleware for protecting routes\r\n\r\n## Installation\r\n\r\n```bash\r\n# Using npm\r\nnpm install @api-buddy/nextauth next-auth\r\n\r\n# Using yarn\r\nyarn add @api-buddy/nextauth next-auth\r\n\r\n# Using pnpm\r\npnpm add @api-buddy/nextauth next-auth\r\n```\r\n\r\n## Quick Start\r\n\r\n1. Run the setup command:\r\n   ```bash\r\n   npx @api-buddy/nextauth\r\n   ```\r\n   This will:\r\n   - Create the necessary API routes\r\n   - Set up the authentication configuration\r\n   - Install required dependencies\r\n   - Configure environment variables\r\n\r\n2. Update your `.env.local` with your authentication providers' credentials:\r\n   ```env\r\n   NEXTAUTH_SECRET=your-secret-here\r\n   NEXTAUTH_URL=http://localhost:3000\r\n   \r\n   # Example: Google OAuth\r\n   GOOGLE_CLIENT_ID=your-google-client-id\r\n   GOOGLE_CLIENT_SECRET=your-google-client-secret\r\n   ```\r\n\r\n3. Wrap your application with the `NextAuthProvider` in your root layout:\r\n   ```tsx\r\n   // app/layout.tsx\r\n   'use client';\r\n   \r\n   import { NextAuthProvider } from '@api-buddy/nextauth';\r\n   \r\n   export default function RootLayout({\r\n     children,\r\n   }: {\r\n     children: React.ReactNode;\r\n   }) {\r\n     return (\r\n       <html lang=\"en\">\r\n         <body>\r\n           <NextAuthProvider>\r\n             {children}\r\n           </NextAuthProvider>\r\n         </body>\r\n       </html>\r\n     );\r\n   }\r\n   ```\r\n\r\n## Usage\r\n\r\n### Protecting Pages\r\n\r\nUse the `useSession` hook to check the authentication status:\r\n\r\n```tsx\r\n'use client';\r\n\r\nimport { useSession } from '@api-buddy/nextauth';\r\n\r\nexport default function Profile() {\r\n  const { data: session } = useSession();\r\n  \r\n  if (!session) {\r\n    return <div>Please sign in to view this page</div>;\r\n  }\r\n  \r\n  return (\r\n    <div>\r\n      <h1>Welcome, {session.user?.name}!</h1>\r\n      <p>Email: {session.user?.email}</p>\r\n    </div>\r\n  );\r\n}\r\n```\r\n\r\n### Server Components\r\n\r\nFor server components, use the `getServerSession` function:\r\n\r\n```tsx\r\nimport { getServerSession } from 'next-auth';\r\nimport { authOptions } from '@/lib/auth';\r\n\r\nexport default async function ProfilePage() {\r\n  const session = await getServerSession(authOptions);\r\n  \r\n  if (!session) {\r\n    return <div>Please sign in to view this page</div>;\r\n  }\r\n  \r\n  return (\r\n    <div>\r\n      <h1>Welcome, {session.user?.name}!</h1>\r\n      <p>Email: {session.user?.email}</p>\r\n    </div>\r\n  );\r\n}\r\n```\r\n\r\n### Middleware Protection\r\n\r\nProtect routes using the built-in middleware:\r\n\r\n```typescript\r\n// middleware.ts\r\nexport { default } from 'next-auth/middleware';\r\n\r\nexport const config = {\r\n  // Protect all routes except auth and static files\r\n  matcher: ['/((?!api|_next/static|_next/image|favicon.ico|auth|public).*)'],\r\n};\r\n```\r\n\r\n## Configuration\r\n\r\nCustomize the authentication by modifying the configuration in `src/lib/auth.ts`:\r\n\r\n```typescript\r\nimport { authConfig } from '@api-buddy/nextauth';\r\n\r\nexport const authOptions = {\r\n  ...authConfig,\r\n  providers: [\r\n    // Add your authentication providers here\r\n  ],\r\n  callbacks: {\r\n    // Customize session and JWT callbacks\r\n  },\r\n  // Other NextAuth.js configuration options\r\n};\r\n```\r\n\r\n## Available Hooks\r\n\r\n### useSession\r\n\r\nGet the current session and status:\r\n\r\n```typescript\r\nconst { data: session, status } = useSession();\r\n```\r\n\r\n### useRequiredSession\r\n\r\nA hook that redirects to the sign-in page if the user is not authenticated:\r\n\r\n```typescript\r\nconst { session, status } = useRequiredSession();\r\n```\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}