Next Auth 4: expected 200 OK with body but no body was returned #1079
-
DescriptionI have a next.js project that relies on msw to mock 3rd party api responses during development and automated tests. This was working fine as long as I used next-auth@3, but after upgrading to next-auth@4 im getting the error you can see in the stacktrace below when using github as an oauth provider. The error's cause seems to be open-id expecting a response body but not getting one. Since it works if msw is not active, i suspect that the auth response from github is somehow intercepted by msw. Im aware that this is not a direct msw bug, but i would really appreciate any pointers to a solution. Im going to try to look into this myself and provide both tickets with infos. How to reproduceI have created this example it is basically the next-auth typescript example & 1 commit that adds msw In a .env file its needed to provide a GITHUB_ID and GITHUB_SECRET. Here are the regarding docs Then, by running (On my machine my cache played pranks on me, so the bug actually did not occur sometimes. Deleting the cache and reloading brings the bug forward) Error Stacktrace
Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
https://github.com/panva/node-openid-client/blob/main/package.json#L74 Open-id client, which is leveraged by next-auth, is not compatible with all node versions. Could it be, that msw somehow runs its own little node instance, that has a wrong version? (Very wild guess 😄 ) |
Beta Was this translation helpful? Give feedback.
-
Hey, @laurenzhonauer. Thanks for raising this. I've looked into your reproduction repository and I found the root cause. It's coming from the Basically, we read the response body during the interception to share it with the consumer via Life-cycle events. Since we read the original response, any downstream consumers can't do that anymore—responses can only be read once. When it comes to Next Auth reading the response to
SolutionsThis issue has been fixed in the newest versions of
MSW does not yet depend on the newest version of the interceptors library, though. This brings you to two potential ways to tackle the issue in your application:
|
Beta Was this translation helpful? Give feedback.
-
@kettanaito Any new insights on this? As I said in my comment, i tried the suggested solution here but did not have success. |
Beta Was this translation helpful? Give feedback.
-
There's at least one issue that may affect this (#1120). We've fixed this in |
Beta Was this translation helpful? Give feedback.
There's at least one issue that may affect this (#1120). We've fixed this in
@mswjs/interceptors
(not released yet) and will propagate it to MSW in #1136.