core
core copied to clipboard
browser.setCookie is not a function` when using `hubBrowser()` in production
Describe the bug
When I try to generate a PDF of a protected Nuxt page using hubBrowser(), authentication fails because I cannot set cookies—browser.setCookie is not defined in the production build.
Steps to reproduce Steps to reproduce the behavior:
- In a Nuxt endpoint:
export default defineEventHandler(async (event) => {
const session_token = getCookie(event, 'better-auth.session_token')
const { page, browser } = await hubBrowser()
browser.setCookie({
name: 'better-auth.session_token',
value: session_token,
domain: 'localhost',
path: '/',
sameParty: true,
httpOnly: true,
secure: false,
})
const id = Number.parseInt(event.context.params!.id) as number
await page.goto(`${getRequestURL(event).origin}/ddt/${id}/_pdf`)
setHeader(event, 'Content-Type', 'application/pdf')
return page.pdf({ format: 'A4' })
})
- Build and deploy to production
- Invoke the api
What is Expected? The hubBrowser() API should expose a setCookie (or equivalent) method so I can pass my session/auth cookies before navigating.
PDF generation succeeds without authentication errors.
The nuxt hub logs
In the develpment enviroment, this works perfectly