How to pass and validate cookies (server<>server) ? (RPC)
I use Sveltekit and hono as an external API.
Most requests coming from the UI are done through XHR, but some requests (like token validation) is done from sveltekit server-side to hono api.
- When the user logs in, a cookie is set on the client (secure, lax).
- When the user close and re-open the site, the token is validated with a server hook. Sveltekit sees the cookies and make a request to hono, but hono doesn't see the cookies (obviously).
I don't want to store too much information in localStorage, so a page refresh require token decryption.
I'm looking for a way to pass down those cookies from svelte server to hono api, but that endpoint might also be called from a browser or something, so for security reason I don't want to use
json
to pass the data preferably. Cookies is the way to go here.
Validator:
Client call:
3 Replies
I'll just resort to a json body and make sure the request is coming from a known internal ip
Cookie is webnative and should be set by the server i don't get what you want to do
You need to set the fetch of honoClient to include credentials
For exemple
I understand, but in this case, hono client is called on the server (SSR side). I realised this is by design cookie-side. The client have the cookies, and the svelte server receive them. I then need to pass them from svelte server side to hono api in a nice way... But I just resorted to a json post and pass them there with some check.