Skip to content

Conversation

huseyingulec
Copy link

🔍Problem

Using the jsonwebtoken package in a Next.js App Router project causes the following error when deploying to the Edge Runtime:

Error: The edge runtime does not support Node.js 'crypto' module.

This occurs because jsonwebtoken relies on Node's native crypto module, which is not available in the Edge runtime environment.

✅ Solution

This PR replaces jsonwebtoken with jose, a fully compliant, modern, and Edge-compatible JWT library. It uses Web Crypto API under the hood, making it safe for use in environments like:

Vercel Edge Functions

Cloudflare Workers

Next.js Edge runtime

🔁 Changes

Replaced jsonwebtoken.sign() with new SignJWT() from jose

Updated JWT creation logic in the NextAuth session() callback

🧪 Result

This change ensures:

✅ Compatibility with Edge Runtime

✅ No more crypto-related runtime errors

✅ Equivalent JWT functionality with standards-compliant library

📌 Note

No changes were made to the file structure or existing auth flow. Only the JWT signing implementation was updated.

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

@huseyingulec huseyingulec requested a review from ndom91 as a code owner July 25, 2025 12:16
Copy link

vercel bot commented Jul 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2025 0:21am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Jul 25, 2025 0:21am

Copy link

vercel bot commented Jul 25, 2025

@huseyingulec is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant