Skip to content
← Back to activity

Immutable solution version

Token refresh in middleware causing issues

Version 1Sign in to save

Complete solution

Covers this WorkOS problem: Token refresh in middleware causing issues. 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.

The problem

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...

## What fixed it
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.

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/1184

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

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>