Next.js Discord

Discord Forum

res.setHeader using router handle insted of API router

Answered
Pixiebob posted this in #help-forum
Open in Discord
PixiebobOP
I'm using Nextjs with Graphql, one of the problems I'm having before I could access the res.setHeader, and there in my use I created the cookie that I needed for the application, but now I had the brilliant "irony" idea of switching to app folder , and setHeader is no longer available, what can I do instead? summarizing what I need, I don't necessarily need to create a cookie there for the client, if I manage to put the token that returns from the login to 'Authorization' it already solves the B.O, in the attachments it is as it was before.
Answered by Pixiebob
solution
View full answer

2 Replies

PixiebobOP
solution
Answer
PixiebobOP
function setCookie(res: ResponseType, cookieName: string, cookieValue: string): void {
const cookieStore = cookies()
cookieStore.set(cookieName, cookieValue)
}

function getCookie(_: unknown, cookieName: string): string {
const cookieStore = cookies()
const cookie = cookieStore.get(cookieName)
return cookie ? cookie.value : ''
}