-
-
Notifications
You must be signed in to change notification settings - Fork 701
Hono RPC in NextJS doesn't include default cookies / headers that fetch does #3734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @jacobsamo Thank you for sharing the repo. But, it is large. Can you create a minimal project to reproduce it and share clear instructions? |
Hey @yusukebe, It is quite a large repo I have gone and created a example repo here: https://github.com/jacobsamo/hono-rpc-nextjs-example it is still quite large as this is how the setup works for my example. The main issue I am facing is when I make a request there is no cookies being sent with that request, cookies can be returned from the sever if added but not sent as the API lives on another port. my question is how do I get this sent across as well. this is what I see in chrome dev tools: I might be missing something with cors policy but not 100% sure. |
Hi @jacobsamo Thank you for the repro. Since the |
@yusukebe that is true, I think the weird part I find is when using it in my expo app it automatically adds the cookies to send to the server (I know these might work a bit differently) I'm thinking the best option is when I set the RPC client in Nextjs I add cookies to the headers Like so: import type { AppType } from "@buzztrip/api/src";
import { env } from "env";
import { hc } from "hono/client";
export const apiClient = hc<AppType>(env.NEXT_PUBLIC_API_URL!, {
headers: {
Authorization: `Bearer ${env.NEXT_PUBLIC_API_SECRET_KEY}`,
Cookie: document.cookie
},
}); |
I see. That means the behavior of the expo is not the same as other const res = await apiClient.api.index.$get(
{
foo: 'bar',
},
{
headers: {
'set-cookie': cookieValues,
},
}
) Anyway, this issue is not a Hono-side bug. |
This issue has been marked as stale due to inactivity. |
Closing this issue due to inactivity. |
What version of Hono are you using?
4.6.11
What runtime/platform is your app running on? (with version if possible)
Cloudflare Workers
What steps can reproduce the bug?
When I import the rpc client from hono and make requests using it, it doesn't pass the cookies in the same request like fetch methods do, in my mobile app it works fine but not my nextjs project for some reason and not sure how to fix it.
In a server environment you can use the
cookies()
and theheaders()
method to add them however I am using this on the client and those are server-only valuesWhat is the expected behavior?
When i make a request the cookie's and any other default header information that fetch sends will also send with the request.
What do you see instead?
Default Headers / cookies is not passed.
Additional information
Repo: https://github.com/jacobsamo/BuzzTrip/tree/improve-web
The text was updated successfully, but these errors were encountered: