Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/e2e/app-dir/use-cache/app/cache-fetch-auth-header/page.tsx
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>
</>
)
}
9 changes: 9 additions & 0 deletions test/e2e/app-dir/use-cache/use-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,13 @@ describe('use-cache', () => {

expect(await browser.elementByCss('#random').text()).toBe(initialValue)
})

it('should override fetch with cookies/auth in use cache properly', async () => {
const browser = await next.browser('/cache-fetch-auth-header')

const initialValue = await browser.elementByCss('#random').text()
await browser.refresh()

expect(await browser.elementByCss('#random').text()).toBe(initialValue)
})
})
Loading