<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gaurav Kumar</title>
    <description>The latest articles on DEV Community by Gaurav Kumar (@gaurav_512).</description>
    <link>https://dev.to/gaurav_512</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3790820%2Fe7298ed3-9082-4c88-9f27-7d2b0e3090af.jpg</url>
      <title>DEV Community: Gaurav Kumar</title>
      <link>https://dev.to/gaurav_512</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gaurav_512"/>
    <language>en</language>
    <item>
      <title>I built a CLI that adds production-ready auth to any Next.js app in under a minute</title>
      <dc:creator>Gaurav Kumar</dc:creator>
      <pubDate>Wed, 25 Feb 2026 04:59:55 +0000</pubDate>
      <link>https://dev.to/gaurav_512/i-built-a-cli-that-adds-production-ready-auth-to-any-nextjs-app-in-under-a-minute-1cbi</link>
      <guid>https://dev.to/gaurav_512/i-built-a-cli-that-adds-production-ready-auth-to-any-nextjs-app-in-under-a-minute-1cbi</guid>
      <description>&lt;p&gt;Every time I started a new Next.js project, I found myself writing the same authentication code over and over.&lt;/p&gt;

&lt;p&gt;JWT setup. bcrypt hashing. httpOnly cookies. Mongoose models. Middleware protection. Login and signup pages. It takes hours to get right and it's the same every single time.&lt;/p&gt;

&lt;p&gt;So I built &lt;strong&gt;nextauthforge&lt;/strong&gt; — a CLI that scaffolds the entire auth system into any Next.js App Router project in under a minute.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx nextauthforge init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Answer a few questions and you're done.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;◆ AUTHFORGE — Next.js Auth Scaffolder

? What is your project name? my-app
? Which database are you using? MongoDB
? Include login &amp;amp; signup pages? Yes
? Include example dashboard ? Yes

✓ Auth files scaffolded
✓ Dependencies installed
✓ AuthForge setup complete!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What gets generated
&lt;/h2&gt;

&lt;p&gt;Running the CLI scaffolds a complete auth system:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API Routes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;POST /api/auth/signup&lt;/code&gt; — register + auto login&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;POST /api/auth/login&lt;/code&gt; — verify credentials + set cookie&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;POST /api/auth/logout&lt;/code&gt; — clear session&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /api/auth/me&lt;/code&gt; — get current user&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Frontend Pages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Landing page&lt;/li&gt;
&lt;li&gt;Login page&lt;/li&gt;
&lt;li&gt;Signup page&lt;/li&gt;
&lt;li&gt;Dashboard (protected)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Utilities:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;lib/jwt.ts&lt;/code&gt; — sign and verify JWT using jose&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lib/hash.ts&lt;/code&gt; — bcrypt helpers&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lib/session.ts&lt;/code&gt; — cookie reader&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lib/dbConfig.ts&lt;/code&gt; — MongoDB connection singleton&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;hooks/useAuth.tsx&lt;/code&gt; — client-side auth state&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;components/ToasterProvider.tsx&lt;/code&gt; — toast notifications&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;proxy.ts&lt;/code&gt; — middleware route protection&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The auth strategy
&lt;/h2&gt;

&lt;p&gt;I made some deliberate choices about how auth works:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JWT in httpOnly cookies — not localStorage.&lt;/strong&gt; This is the right call for security. httpOnly cookies can't be accessed by JavaScript so they're immune to XSS attacks. localStorage tokens are a common mistake.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;jose instead of jsonwebtoken.&lt;/strong&gt; Next.js middleware runs on the Edge Runtime which doesn't support Node.js built-ins. jsonwebtoken breaks in middleware. jose is Web Crypto API compatible and works everywhere in Next.js.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;bcrypt with 12 rounds.&lt;/strong&gt; Intentionally slow to make brute force attacks impractical.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Generic error messages.&lt;/strong&gt; Both "user not found" and "wrong password" return the same "Invalid credentials" message. This prevents email enumeration attacks where an attacker can figure out which emails are registered.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's coming next
&lt;/h2&gt;

&lt;p&gt;This is v1.0 and there's a lot more planned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL + Prisma&lt;/strong&gt; support&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Refresh tokens&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google OAuth&lt;/strong&gt; — &lt;code&gt;npx nextauthforge add google&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitHub OAuth&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Email verification flow&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx nextauthforge init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;npm → &lt;a href="https://www.npmjs.com/package/nextauthforge" rel="noopener noreferrer"&gt;npmjs.com/package/nextauthforge&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GitHub → &lt;a href="https://github.com/Gauravkumar512/authforge" rel="noopener noreferrer"&gt;github.com/Gauravkumar512/authforge&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Would love feedback from the community. If you run into any issues or have feature requests, open an issue on GitHub.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built with Next.js 14+, MongoDB, jose, bcryptjs, and a lot of copy-pasting the same auth code one too many times.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cli</category>
      <category>nextjs</category>
      <category>showdev</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
