mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #73] Docs: recommended Clerk auth migration pattern (@clerk/backend + @clerk/react) #19
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#19
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @solracnyc on GitHub (Feb 25, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/73
Context
vinext's compatibility map correctly flags
@clerk/nextjsas unsupported. We hit this during migration —import { auth } from '@clerk/nextjs/server'crashes withrequire is not definedbecause the ESM build has a CJS dependency chain (require("server-only")).We successfully migrated by splitting Clerk usage into two packages that work cleanly with vinext:
@clerk/backend—verifyToken()for JWKS-verified JWT auth,createClerkClient()for the Clerk API@clerk/react(via@clerk/nextjsclient-only imports likeClerkProvider,SignIn,useAuth) — these already work fine since they're React components, not server importsclerkMiddlewarefrom@clerk/nextjs/serverstill works inproxy.tssince vinext handles middleware in a separate contextWhat we built
A drop-in
auth()replacement (~60 lines) that:x-clerk-auth-tokenandx-clerk-auth-statusheaders (set byclerkMiddleware)@clerk/backend'sverifyToken()(JWKS cached after first call)@clerk/nextjs/server'sauth()—userId,orgId,orgRole,has(),redirectToSignIn()This let us swap
import { auth } from '@clerk/nextjs/server'→import { auth } from '@/lib/auth'across 16 files with zero behavior change. All 197 tests pass with the same mock shapes.Request
Would it be helpful to document this pattern in vinext's docs or compatibility guide? Clerk is a popular auth provider for Next.js apps, so other users migrating to vinext will likely hit the same issue. We're happy to contribute a docs PR if there's interest.
Environment
@SuperJakov commented on GitHub (Feb 26, 2026):
If possible, it would be much better if we got
require()support@solracnyc commented on GitHub (Feb 28, 2026):
Agreed — native
require()support would be the cleanest path. Great to see @nikosdouvlis already tackling this on the Clerk side with clerk/javascript#7954, which makes@clerk/nextjsESM-safe for non-Node.js runtimes like Workers/vinext.We'll test with the new
@clerk/nextjsversion once it ships. If it works cleanly, the docs PR we offered may not be needed — or could be simplified to a one-liner in the compatibility notes.In the meantime, our
@clerk/backendadapter pattern (~60 lines) works today for anyone who needs Clerk auth on vinext before that fix lands. Happy to contribute docs if it's still useful.@zebp commented on GitHub (Mar 1, 2026):
This should be fixed with #198 which landed in v0.0.16, please give it another try
@nikosdouvlis commented on GitHub (Mar 2, 2026):
Thanks a lot for initial exploration @solracnyc :) we plan to tackle this one the Clerk side with changes in
@clerk/nextjs(or a new package, I can't share details yet as I'm still exploring our options).As for the
requirefix in0.0.16is definitely a step towards the right direction, thank you @zebp!Posting here for visibility as I haven't been able to dive deeper yet (plan to work on this more within the next few hours), but I'm still getting the following error running
vite dev(same results when trying to deploy to CF Workers):The test app above uses
vintext@0.0.18and@clerk/nextjs@canary- build passes with the changes from https://github.com/clerk/javascript/pull/7954 but we still have middleware-level compat issues of course.@solracnyc commented on GitHub (Mar 6, 2026):
Thanks @zebp! We're currently pinned to
~0.0.15in production. We'll retest on a preview branch against the latest vinext release (0.0.21) and report back with dev/build/deploy results for native@clerk/nextjson Workers.We're also tracking clerk/javascript#7954 — noted that @nikosdouvlis reported build passes but
vite devand Workers deploy still fail as of vinext 0.0.18 + canary Clerk. Will include that combination in our test matrix.