-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need custom fetch options for native fetch #262
Comments
Heya @devjmetivier - thanks for opening the issue. @chris-stytch actually ran into this internally the other day 😞. As an immediate workaround, you can modify the function monkeyPatchStytchClientSettings(client: ...) {
/* eslint-disable */
const cl = <any>client;
/* eslint-enable */
cl.fetchConfig.cache = 'no-store';
} It's a little icky, but it should do the trick. You can also call a dynamic function like Regarding changing the Stytch SDK itself - I have a few questions around implementation that I'll try to get answered:
|
Auth0's Node SDK experiences the same issue, but they allow a custom fetcher (as opposed to a custom config for fetch). Details on how they do that👇 Here they start by adding https://github.com/auth0/node-auth0/blob/master/src/lib/models.ts#L8-L42 And this moves up the chain eventually to their Auth Client options... https://github.com/auth0/node-auth0/blob/master/src/auth/base-auth-api.ts#L17-L25 And finally gets passed down the chain where they'll either use your custom fetcher, or native fetch: https://github.com/auth0/node-auth0/blob/master/src/lib/runtime.ts#L24-L52
This is the part where I would inject my opinion. Rather than sending along fetch config options, I'd prefer to pass my own custom fetcher entirely. But I also recognize the following:
I'm also not even sure what the purpose of undici is in the Stytch SDK anywaysThe stytch-node/lib/shared/index.ts Line 36 in a0eae9b
TLDR; actual answer to your last question: Fetch options should just go on the |
We don't use
That's probably the most robust solution for power users. We were hoping we could avoid the complexity of custom fetchers now, since Node 18 made the
There are valid API calls that could be cached - for example, In #266 we're experimenting with adding custom options to requests. If we stick with that approach, passing in |
Related: supabase/supabase-js#725 |
Totally. I don't personally/professionally use custom fetchers often anyways. Sticking with adding custom fetch config options for now is a great start.
This is a great point. The only thing I'll add is that |
I agree completely. #271 should do just that and resolve the immediate issue with NextJS v13+. I'll open up a separate issue to track if anyone does want to cache responses, and would like the ability to pass arbitrary options into native fetch. |
Frameworks like Next.js modify the native fetch implementation to add caching strategies to individual requests (server side). This, in the case of the Stytch Node SDK, creates an issue when making native fetch requests.
For example:
A call using the SDK such as:
... will work fine on the first attempt, and the user will receive their OTP code. However, if a second request is made with the exact same parameters (email in this case), it will result in a cache hit in Next.js/Vercel and the request won't actually go out to Stytch to complete the request, but instead returns a cached response. No second OTP code is sent.
stytch-node/lib/shared/client.ts
Lines 55 to 60 in 2479bd3
☝️ Here is where the
fetch
configurations are created. For Next.js, special options need to be passed in order to prevent the above behaviors from occurring.Please let me know if a reproduction is required, or if it's preferable I can make a contribution to the SDK to add the ability to pass custom fetch arguments.
The text was updated successfully, but these errors were encountered: