npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@0ju1c3-oss/next-auth-cli

v1.0.3

Published

CLI tool to automatically setup NextAuth.js authentication in Next.js App Router projects

Readme

@0ju1c3-oss/next-auth-cli

A CLI tool to automatically setup NextAuth.js authentication in Next.js App Router projects.

Features

  • 🚀 Quick Setup: Automatically generates all necessary NextAuth.js files
  • 📦 Auto-Install: Automatically installs next-auth@beta if not already present
  • 🔍 Smart Detection: Detects src/ directory, App Router structure, and package manager (bun/npm/yarn/pnpm)
  • 🎨 Ready-to-use Components: Pre-built login button and user profile components
  • 🔒 Protected Routes: Middleware configuration with example protected routes
  • 📝 TypeScript Support: All generated files are TypeScript-ready
  • 🔐 Authentication Providers: Currently ships with Google OAuth (more providers coming soon!)

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.

Installation

As a dev dependency (recommended)

bun add -d @0ju1c3-oss/next-auth-cli

or

npm install -D @0ju1c3-oss/next-auth-cli

Global installation

bun add -g @0ju1c3-oss/next-auth-cli

Usage

Navigate to your Next.js project root and run:

bunx next-auth-setup

or with npx:

npx @0ju1c3-oss/next-auth-cli

What Gets Generated

The CLI creates the following files in your project:

1. Authentication Configuration

  • auth.ts (or src/auth.ts) - NextAuth.js configuration (currently: Google OAuth provider)

2. Middleware

  • middleware.ts (or src/middleware.ts) - Route protection for /dashboard/* and /profile/*

3. API Route

  • app/api/auth/[...nextauth]/route.ts - NextAuth.js route handler

4. Components

  • components/login-button.tsx - Sign in/out button component
  • components/user-profile.tsx - User profile display component

5. Environment Template

  • .env.local.example - Template for required environment variables

Post-Installation Steps

After running the CLI, follow these steps:

Note: The CLI automatically installs next-auth@beta for you if it's not already in your project!

1. Setup Environment Variables

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

2. Get Google OAuth Credentials

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Google+ API
  4. Go to CredentialsCreate CredentialsOAuth 2.0 Client ID
  5. Add authorized redirect URI:
    http://localhost:3000/api/auth/callback/google
  6. Copy the Client ID and Client Secret to your .env.local

3. Wrap Your App with SessionProvider

Update 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>
  )
}

4. Use the Components

import LoginButton from '@/components/login-button'
import UserProfile from '@/components/user-profile'

export default function Page() {
  return (
    <div>
      <LoginButton />
      <UserProfile />
    </div>
  )
}

Protected Routes

The generated middleware protects these routes by default:

  • /dashboard/* - Dashboard pages
  • /profile/* - Profile pages

Unauthenticated users will be redirected to the sign-in page.

Customizing Protected Routes

Edit middleware.ts to add or remove protected routes:

export const config = {
  matcher: ["/dashboard/:path*", "/profile/:path*", "/admin/:path*"],
}

Requirements

  • Next.js: >=13.0.0 (App Router)
  • React: >=18.0.0
  • NextAuth.js: >=5.0.0
  • Bun or Node.js: >=18.0.0

Project Structure Support

The CLI automatically detects and adapts to your project structure:

With src/ directory

your-project/
├── src/
│   ├── app/
│   │   └── api/auth/[...nextauth]/route.ts
│   ├── auth.ts
│   └── middleware.ts
└── components/
    ├── login-button.tsx
    └── user-profile.tsx

Without src/ directory

your-project/
├── app/
│   └── api/auth/[...nextauth]/route.ts
├── auth.ts
├── middleware.ts
└── components/
    ├── login-button.tsx
    └── user-profile.tsx

Troubleshooting

Error: Not a Next.js project

Ensure your package.json includes next as a dependency:

{
  "dependencies": {
    "next": "^14.0.0"
  }
}

Error: App Router not found

This CLI requires Next.js App Router (app/ directory). Pages Router is not currently supported.

OAuth Error: redirect_uri_mismatch

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

License

ISC

Future Roadmap

See TODO.md for planned features including:

  • Multiple authentication providers (GitHub, Discord, Twitter, Credentials, etc.)
  • Configuration file support (next-auth-cli.json)
  • Interactive setup mode
  • Pages Router support
  • Database session adapters
  • And more!

Contributing

Issues and pull requests are welcome! Visit the GitHub repository.

Author

@0ju1c3