supertokens / supertokens-node

Node SDK for SuperTokens core
https://supertokens.com
Other
278 stars 72 forks source link

fix: Add workaround for unsupported 'cache' field in Cloudflare Workers #835

Closed anku255 closed 1 month ago

anku255 commented 1 month ago

Summary of change

Add workaround for unsupported 'cache' field in Cloudflare Workers

If a fetch request fails due to the 'cache' field not being implemented in Cloudflare Workers, retry the request without the 'cache' field. More info: https://github.com/cloudflare/workerd/issues/698

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!)

Documentation changes

(If relevant, please create a PR in our docs repo, or create a checklist here highlighting the necessary changes)

Checklist for important updates

ngoquoc commented 2 weeks ago

Not sure if it's because of recent changes in Cloudflare runtime or not, but the error returned since couple of days ago:

Error: The 'cache' field on 'RequestInitializerDict' is not implemented.

It seems that the error is not thrown where Supertoken catches as I debugged and it could never reach catch block. I tried the following and it works:

const fetchFunction = typeof fetch !== "undefined" ? fetch : crossFetch;
    try {
        delete init.cache;
        return fetchFunction(input, init);
    } catch (e) {
        // it could never reach here
    }

@rishabhpoddar @anku255 Would it make sense to have a setting flag to enable/disable adding cache to init object behavior, so users have control over which behavior to use?

anku255 commented 2 weeks ago

@ngoquoc I am not able to reproduce this. Can you share your supertokens-node and wrangler version?

We also have a cf-example app. You can try that and see if you are able to reproduce this issue there.

ngoquoc commented 2 weeks ago

@anku255 I'm using "supertokens-node": "^18.0.0" and "wrangler": "^3.60.3".

I also deployed the example app (respecting the versions in package-lock) and could reproduce the same error. Please see the full error log: cf-init-cache-error-log.json

anku255 commented 2 weeks ago

Thank you @ngoquoc

It seems that error is producible after deployment but not locally using the Wrangler CLI. I will be taking a look soon. Will keep you updated on the same thread.

anku255 commented 2 weeks ago

@ngoquoc We have released a fix in v18.0.1. You can try that and let us know.

ngoquoc commented 1 week ago

@anku255 thank you very much. Tried 18.0.1 and it works perfectly.