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
alexmartos
alexmartos15mo ago
You can modify it with ‘headers.set()’
West side ⁉
West side ⁉OP15mo ago
I'm trying to append the header "location" for example, although when inspecting the response, nothing is added
alexmartos
alexmartos15mo ago
Oh the response. You would have to run ‘options.res.headers.set()’. Res🙂
West side ⁉
West side ⁉OP15mo ago
Interesting, options.res is undefined for some reason from tRPC Although would check why sometime
alexmartos
alexmartos15mo ago
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.
West side ⁉
West side ⁉OP15mo ago
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.
alexmartos
alexmartos15mo ago
Yeah, just curios. What type of headers do you have to set?
West side ⁉
West side ⁉OP15mo ago
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)
alexmartos
alexmartos15mo ago
Yeah, dosent seem like it unfortunally.
Want results from more Discord servers?
Add your server