Authentication in Next.js 14: NextAuth v5, Clerk, or Roll Your Own?
Next.jsBackendFrontend

Authentication in Next.js 14: NextAuth v5, Clerk, or Roll Your Own?

After shipping auth on 10+ Next.js projects, here's how I decide between NextAuth (Auth.js), Clerk, and custom JWT — with the gotchas each path hides.

HJ
Hassan Javed
April 2026
11 min read

The "what auth library" question

Every Next.js project starts with this. Every senior engineer has an opinion. Most opinions are wrong because they generalize.

The right answer depends on three things: your team's compliance needs, your willingness to operate auth infrastructure, and how many auth providers you actually need to support.

After shipping auth on 10+ Next.js production apps in the last 18 months, here's the decision framework I use, with the foot-guns I tripped over on each path.

Option 1: NextAuth (Auth.js v5)

The default. Almost every Next.js app starts here.

Strengths:

50+ OAuth providers out of the box
Database session support (Postgres, MongoDB, Drizzle, Prisma adapters)
Free and open source
v5 finally has solid App Router support (v4 was painful)
No vendor lock-in

Weaknesses:

Documentation has historically been confusing (improving)
Magic link email auth requires you to provide an email service (Resend, SendGrid)
Sessions in JWT mode can grow large; database sessions need a DB
2FA is not built in — you wire it yourself

Pick when:

You want OAuth plus email or password and own your DB
Compliance is normal (no HIPAA or SOC 2 fire drill required)
Team has SQL or NoSQL experience
You're cost-conscious

Option 2: Clerk

The hosted option. Beautifully integrated.

Strengths:

Drop-in components: SignIn, SignUp, UserProfile — they just work
Best-in-class App Router SDK (middleware-level auth integration)
MFA, magic links, social auth, organizations, RBAC — all built in
SOC 2 compliant out of the box
Their support is genuinely fast

Weaknesses:

Costs 25 dollars per month at the entry tier, scales with MAU
Data lives in Clerk's database, not yours (some teams hate this)
Vendor lock-in is real; migrating off is non-trivial

Pick when:

B2B SaaS where login UX matters
You need organizations and roles immediately
Compliance demands are formal (SOC 2)
Team is small and operating auth is a distraction

Option 3: Custom JWT

Roll your own. Less common in 2026, but the right answer sometimes.

Strengths:

Complete control over flow, claims, expiration, refresh logic
No third-party dependency
Auth data lives entirely in your DB
Free

Weaknesses:

You will get something wrong (refresh token rotation, CSRF, session invalidation)
Maintenance burden over years is real
Implementing OAuth correctly is non-trivial
Most teams don't have someone who can confidently audit it

Pick when:

You have very specific token claims needs (token-gated content, blockchain-derived identity)
Your DB is already the source of truth and you don't want a sync problem
You have senior auth experience on the team
You're explicitly building auth as a feature

Specific recipes that work

MERN SaaS, B2B, under 10K users

NextAuth v5 plus Postgres adapter (Prisma or Drizzle). Magic links plus Google OAuth. Database sessions. Add 2FA at the application layer when needed. Estimated effort: 1-2 days for v1, 1 week for production polish.

MERN SaaS, B2B, growth-stage

Clerk. Pay the 25 dollars per month, get organizations plus RBAC plus MFA plus audit logs for free. Skip the build vs buy debate. Estimated effort: 4-8 hours total.

Consumer mobile app with Next.js backend

NextAuth v5 with JWT mode plus your custom email provider. The mobile app holds the access token, refreshes via your API. Estimated effort: 2-3 days.

Web3 dApp where users connect wallets

Custom JWT with SIWE (Sign-In with Ethereum). NextAuth v5 has a SIWE provider but it's not as polished as a hand-rolled version. I usually roll a custom one here because the claims structure matters. Estimated effort: 1 week for v1.

The gotchas

What bit me on each path:

NextAuth gotcha

Session callbacks run on every request. If you put expensive DB queries in your session callback (to enrich claims), every page load triggers them. Memoize aggressively or move to JWT-only mode.

Clerk gotcha

Webhook delivery for user events. Clerk fires webhooks when users sign up, update, or delete. If your DB lives separately, you need a webhook handler to sync. Easy to forget; hard to debug when out of sync.

Custom JWT gotcha

Refresh token rotation under concurrent requests. If two requests fire simultaneously with the same refresh token, naive implementations issue two new tokens and invalidate one. The user gets logged out. Mutex per refresh token solves it.

My defaults in 2026

Project typeAuth
MERN SaaS (B2B)NextAuth v5 if cost-sensitive, Clerk if speed matters
Consumer appNextAuth v5
Web3 or wallet-basedCustom JWT with SIWE
Enterprise SAMLWorkOS or Clerk B2B
Internal tool or adminNextAuth v5 with email provider only

TL;DR

NextAuth v5: default for cost-sensitive teams who own their DB
Clerk: default for B2B SaaS where you can pay for time saved
Custom JWT: only when you have a specific reason (Web3, very custom claims)
WorkOS: when SAML or SCIM is required

If you're starting a Next.js project and want a senior to architect auth correctly the first time, contact me.

Related Reads

You might also like