sergiodxa / remix-auth-oauth2

A OAuth2Strategy for Remix Auth
https://sergiodxa.github.io/remix-auth-oauth2/
MIT License
150 stars 56 forks source link

"Unexpected end of JSON input" error due to unimplemented response.clone in bun. #66

Open coji opened 11 months ago

coji commented 11 months ago

I implemented Google login using remix-auth-oauth2 and remix-auth-google, based on remix-on-bun by @sergiodxa . However, I encountered an "Unexpected end of JSON input" error when calling authenticator.authenticate in the callback.

Upon investigation, I found that the issue is due to the lack of Response.clone implementation in Bun. This causes an error in response.json() when getAccessToken tries to read from a cloned response created in fetchAccessToken.

While waiting for Bun to implement this might be an option, it seems unnecessary to clone the response in fetchAccessToken in the first place.

I've managed to get it working by applying the following patch on my end. Is cloning really necessary?

diff --git a/node_modules/remix-auth-oauth2/build/index.js b/node_modules/remix-auth-oauth2/build/index.js
index 78f2712..1597705 100644
--- a/node_modules/remix-auth-oauth2/build/index.js
+++ b/node_modules/remix-auth-oauth2/build/index.js
@@ -251,7 +251,7 @@ class OAuth2Strategy extends remix_auth_1.Strategy {
             let body = await response.text();
             throw body;
         }
-        return await this.getAccessToken(response.clone());
+        return await this.getAccessToken(response);
     }
 }
 exports.OAuth2Strategy = OAuth2Strategy;