Observed since 20 Oct, 22:11 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
@0ju1c3-oss/next-auth-cli
CLI tool to automatically setup NextAuth.js authentication in Next.js App Router projects
A CLI tool to automatically setup NextAuth.js authentication in Next.js App Router projects.
next-auth@beta if not already presentsrc/ directory, App Router structure, and package manager (bun/npm/yarn/pnpm)Note: This package currently generates Google OAuth setup. Support for multiple providers (GitHub, Discord, Credentials, etc.) and custom configuration files is planned. See TODO.md for the full roadmap.
bun add -d @0ju1c3-oss/next-auth-cli
or
npm install -D @0ju1c3-oss/next-auth-cli
bun add -g @0ju1c3-oss/next-auth-cli
Navigate to your Next.js project root and run:
bunx next-auth-setup
or with npx:
npx @0ju1c3-oss/next-auth-cli
The CLI creates the following files in your project:
auth.ts (or src/auth.ts) - NextAuth.js configuration (currently: Google OAuth provider)middleware.ts (or src/middleware.ts) - Route protection for /dashboard/* and /profile/*app/api/auth/[...nextauth]/route.ts - NextAuth.js route handlercomponents/login-button.tsx - Sign in/out button componentcomponents/user-profile.tsx - User profile display component.env.local.example - Template for required environment variablesAfter running the CLI, follow these steps:
Note: The CLI automatically installs
next-auth@betafor you if it's not already in your project!
Create a .env.local file:
cp .env.local.example .env.local
Add your credentials:
AUTH_SECRET=your-secret-key-here
AUTH_GOOGLE_ID=your-google-client-id
AUTH_GOOGLE_SECRET=your-google-client-secret
Generate a secret:
openssl rand -base64 32
http://localhost:3000/api/auth/callback/google
.env.localUpdate your app/layout.tsx:
import { SessionProvider } from "next-auth/react"
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<SessionProvider>
{children}
</SessionProvider>
</body>
</html>
)
}
import LoginButton from '@/components/login-button'
import UserProfile from '@/components/user-profile'
export default function Page() {
return (
<div>
<LoginButton />
<UserProfile />
</div>
)
}
The generated middleware protects these routes by default:
/dashboard/* - Dashboard pages/profile/* - Profile pagesUnauthenticated users will be redirected to the sign-in page.
Edit middleware.ts to add or remove protected routes:
export const config = {
matcher: ["/dashboard/:path*", "/profile/:path*", "/admin/:path*"],
}
The CLI automatically detects and adapts to your project structure:
src/ directoryyour-project/
├── src/
│ ├── app/
│ │ └── api/auth/[...nextauth]/route.ts
│ ├── auth.ts
│ └── middleware.ts
└── components/
├── login-button.tsx
└── user-profile.tsx
src/ directoryyour-project/
├── app/
│ └── api/auth/[...nextauth]/route.ts
├── auth.ts
├── middleware.ts
└── components/
├── login-button.tsx
└── user-profile.tsx
Ensure your package.json includes next as a dependency:
{
"dependencies": {
"next": "^14.0.0"
}
}
This CLI requires Next.js App Router (app/ directory). Pages Router is not currently supported.
Make sure your Google OAuth redirect URI matches exactly:
http://localhost:3000/api/auth/callback/google
For production, add:
https://yourdomain.com/api/auth/callback/google
ISC
See TODO.md for planned features including:
next-auth-cli.json)Issues and pull requests are welcome! Visit the GitHub repository.
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
chalkEnvironment{
"local_name": "chalk",
"alias": false,
"peer_metadata": null
} | ^5.3.0 | runtime |
fs-extraEnvironment{
"local_name": "fs-extra",
"alias": false,
"peer_metadata": null
} | ^11.2.0 | runtime |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^5.7.2 | development |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^22.10.5 | development |
@types/fs-extraEnvironment{
"local_name": "@types/fs-extra",
"alias": false,
"peer_metadata": null
} | ^11.0.4 | development |
nextEnvironment{
"local_name": "next",
"alias": false,
"peer_metadata": null
} | >=13.0.0 | peer |
reactEnvironment{
"local_name": "react",
"alias": false,
"peer_metadata": null
} | >=18.0.0 | peer |
next-authEnvironment{
"local_name": "next-auth",
"alias": false,
"peer_metadata": null
} | >=5.0.0 | peer |
Source distribution
{
"shasum": "5cbb1943581e194f8b14c632df728705e8802744",
"tarball": "https://registry.npmjs.org/@0ju1c3-oss/next-auth-cli/-/next-auth-cli-1.0.1.tgz",
"fileCount": 4,
"integrity": "sha512-s0vfaVJgrGcBAwd6vMST9XFKcSCJlyq4OVfRVUZq+LU6m36owKSpBRo/BJh+i6vAis6jPuolu1+Ativ3QOAYwQ==",
"signatures": [
{
"sig": "MEYCIQC9LC7PTp1atVsgjd2gof3Q8nR/nughjTC1/BxujdFXowIhAIgsxOLlCeX/MURd5yZMwNaYgPOntGIedFIaUCgnO6By",
"keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
}
],
"unpackedSize": 96953
}Observed since 20 Oct, 22:11 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:0e604f682f903c5ceb97f7c96b42e8a9cfa6fe4537bceffdefa3d470bc627893