Skip to content
Discussion options

You must be logged in to vote

Yes, a module-scoped cache on a Next.js server can be shared by multiple requests, so authenticated responses need to be partitioned correctly.

The recommended HTTP solution is for the API to return:

Vary: Authorization

Axios Cache Interceptor handles this automatically with the default vary: true, creating separate cache entries for different authorization headers.

Make sure the interceptor adding Authorization runs before the cache interceptor. Axios request interceptors run in reverse registration order, so register the auth interceptor after setupCache():

const api = setupCache(axios.create());

api.interceptors.request.use((config) => {
  config.headers.set("Authorization", `Bearer ${g…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by arthurfiorette
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #980 on March 04, 2026 23:38.