Accessing headers from TRPC and modifying them
In the latest Create-T3-App it seems to be passing headers along the context
but modifying them does nothing
any idea on how to modify?
9 Replies
You can modify it with ‘headers.set()’
I'm trying to append the header "location" for example, although when inspecting the response, nothing is added
Oh the response. You would have to run ‘options.res.headers.set()’. Res🙂
Interesting, options.res is undefined for some reason from tRPC
Although would check why sometime
Yeah, I tried it out now. I forgot Route handlers does not provide the
res
object and header()
cannot set headers. I also tried returning a NextResponse. I tried with NextResponse but could not get it working either, don't know if their is a workaround.Yep, I honestly was trying to do it for
Lucia
but had no luck
ended up using a casual api route for logging in/out, and tRPC for everything else.Yeah, just curios. What type of headers do you have to set?
cookies but I have changed the stack once againn
I was giving lucia a try
too bad
switched back to iron-session
still same issue persists, opts.res is undefined?! for some reason
So here's what I've got to know after a bit of investigation:
With the new app directory, T3 would create you an app that won't pass
res
to TRPC, this you can't modify the response.
This would affect many libraries such as Lucia and iron-session as they require access to res
(to modify headers and add appropriate cookies)Yeah, dosent seem like it unfortunally.