Skip to content
Discussion options

You must be logged in to vote

This is a known pain point with Auth.js v5 + App Router. The core issue is that the jwt callback has no built-in concurrency control, and Next.js 16 fires parallel RSC requests on navigation. Here's how to solve each part:

1. Single-flight token refresh — deduplicate with a shared Promise

The jwt callback runs in the same Node.js process (assuming self-hosted, not Edge), so module-level state works:

// lib/auth-refresh.ts
let inflightRefresh: Promise<any> | null = null;

export async function refreshAccessTokenOnce(token: any) {
  if (inflightRefresh) return inflightRefresh;

  inflightRefresh = refreshAccessToken(token).finally(() => {
    inflightRefresh = null;
  });

  return inflight…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 3rr0r467
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants