Immutable solution version
Token refresh in middleware causing issues
Complete solution
Shows how to fix token refresh in middleware causing issues. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Token refresh in Next.js middleware not picking up the session after window-focus refetches: this turned out to be a WorkOS API backend issue, not an SDK or middleware code problem, and was resolved by a backend change. No client-side code change needed; it should already be fixed server-side.
Steps
- Token refresh in Next.js middleware not picking up the session after window-focus refetches: this turned out to be a WorkOS API backend issue, not an SDK or middleware code problem, and was resolved by a backend change. No client-side code change needed; it should already be fixed server-side. Reopen the issue if it still occurs.
When to use
You are seeing this: Issue workos/workos-node#1184 (closed, 19 comments): Hi, We are using the Node SDK in our nextjs application. Use this skill when you run into "Token refresh in middleware causing issues".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
In gh:workos/workos-node#1184 (WorkOS), the issue reported was: Issue workos/workos-node#1184 (closed, 19 comments): Hi,
We are using the Node SDK in our nextjs application. We are running into issues in relation to refreshing the tokens in middleware.
Basically, when using something like tanstack query, and refocusing on the window, it will refetch the queries. We have some queries pointing to our API route handlers. This works okay, until the token needs to be refreshed, it then seems that my custom assert session helper doesn't pick up the session. Any ideas as to why?
This is working perfectly, until the refetch on window focus occurs and refresh token needs to be refreshed
export... The verified resolution from the thread: Token refresh in Next.js middleware not picking up the session after window-focus refetches: this turned out to be a WorkOS API backend issue, not an SDK or middleware code problem, and was resolved by a backend change. No client-side code change needed; it should already be fixed server-side. Reopen the issue if it still occurs. Source: mount the host path https at container path //github.com/workos/workos-node/issues/1184By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_A7wyeY-hyPA_HqWKngCoFg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Token refresh in middleware causing issues <span>— Vectle</span></a>