Skip to content

Commit 034bee0

Browse files
authored
feat: explicit cache: no-store in fetch (#847)
Next.js polyfills the `fetch` on the server side to always cache (what's known as their Data Cache) responses. Quote: > Next.js has a built-in Data Cache that persists the result of data fetches across incoming server requests and deployments. This is possible because Next.js extends the native fetch API to allow each request on the server to set its own persistent caching semantics. > > Good to know: In the browser, the cache option of fetch indicates how a request will interact with the browser's HTTP cache, in Next.js, the cache option indicates how a server-side request will interact with the server's Data Cache. This is _incredibly dangerous_ for Auth use cases. Thankfully, it appears that using the default client uses `@supabase/node-fetch` in such a circumstance which should not be affected by the issue. However, if developers do choose to switch back to the native `fetch` in Next.js the library must inform that HTTP client that there should be no caching under any circumstance on Auth responses. Opting out docs: https://nextjs.org/docs/app/building-your-application/caching#opting-out-1
1 parent 9ea94fe commit 034bee0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib/fetch.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ export async function _request(
118118
fetcher,
119119
method,
120120
url + queryString,
121-
{ headers, noResolveJson: options?.noResolveJson },
121+
{
122+
headers,
123+
noResolveJson: options?.noResolveJson,
124+
},
122125
{},
123126
options?.body
124127
)
@@ -138,7 +141,12 @@ async function _handleRequest(
138141
let result: any
139142

140143
try {
141-
result = await fetcher(url, requestParams)
144+
result = await fetcher(url, {
145+
...requestParams,
146+
// UNDER NO CIRCUMSTANCE SHOULD THIS OPTION BE REMOVED, YOU MAY BE OPENING UP A SECURITY HOLE IN NEXT.JS APPS
147+
// https://nextjs.org/docs/app/building-your-application/caching#opting-out-1
148+
cache: 'no-store',
149+
})
142150
} catch (e) {
143151
console.error(e)
144152

0 commit comments

Comments
 (0)