forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for fetch with auth in use cache (vercel#71768)
This ensures we are properly caching fetch inside of use cache even if it uses `Authorzation` and comes after cookies() access.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
test/e2e/app-dir/use-cache/app/cache-fetch-auth-header/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { cookies } from 'next/headers' | ||
import React from 'react' | ||
|
||
async function getData() { | ||
'use cache' | ||
|
||
return fetch('https://next-data-api-endpoint.vercel.app/api/random', { | ||
headers: { | ||
Authorization: `Bearer ${process.env.MY_TOKEN}`, | ||
}, | ||
}).then((res) => res.text()) | ||
} | ||
|
||
export default async function Page() { | ||
const myCookies = await cookies() | ||
const id = myCookies.get('id')?.value | ||
|
||
return ( | ||
<> | ||
<p>index page</p> | ||
<p id="random">{await getData()}</p> | ||
<p id="my-id">{id || ''}</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters