Should event: APIevent have client cookies on SSR?

import { type APIEvent } from "@solidjs/start/server/types";
import { app } from "./elysia";

const handler = async (event: APIEvent) => {
return await app.handle(event.request);
};

export const GET = handler;
export const POST = handler;
export const PUT = handler;
export const PATCH = handler;
export const DELETE = handler;
import { type APIEvent } from "@solidjs/start/server/types";
import { app } from "./elysia";

const handler = async (event: APIEvent) => {
return await app.handle(event.request);
};

export const GET = handler;
export const POST = handler;
export const PUT = handler;
export const PATCH = handler;
export const DELETE = handler;
In following code headers only have these
Headers {
"connection": "keep-alive",
"user-agent": "Bun/1.0.26",
"accept": "*/*",
"host": "localhost:3000",
"accept-encoding": "gzip, deflate, br",
}
Headers {
"connection": "keep-alive",
"user-agent": "Bun/1.0.26",
"accept": "*/*",
"host": "localhost:3000",
"accept-encoding": "gzip, deflate, br",
}
7 Replies
Massukka
Massukka6mo ago
What I am asking, should clients cookies be forwarded to bun?
Brendonovich
Brendonovich6mo ago
During SSR API routes won't receive cookies, no, since it's not the client making the request You need to pass through the cookies manually inside your solid query fetch use server functions avoid this since they don't do a server -> server request during SSR, instead they are just called directly, reusing the Request from the client
Massukka
Massukka6mo ago
Big thanks. Yeah that makes sense. It's kind of like using axios you need to remember to add "usecredentials".
Brendonovich
Brendonovich6mo ago
hmm isn't that a client-side cors thing?
Massukka
Massukka6mo ago
Sorry, lol
const authQuery = createQuery(() => ({
queryKey: ["auth"],
queryFn: async () => {
const event = isServer ? getRequestEvent() : null;
return handleEden(
await eden.api.auth.status.get({
$fetch: {
headers: event
? {
...Object.fromEntries(event?.request.headers),
}
: "",
},
})
);
},
}));
const authQuery = createQuery(() => ({
queryKey: ["auth"],
queryFn: async () => {
const event = isServer ? getRequestEvent() : null;
return handleEden(
await eden.api.auth.status.get({
$fetch: {
headers: event
? {
...Object.fromEntries(event?.request.headers),
}
: "",
},
})
);
},
}));
Got it working, but wanted to see if you recommend some other way to do this
Brendonovich
Brendonovich6mo ago
yeah i'd imagine it'd look something like this - though could you call eden inside a server function? you wouldn't have to mess with any of this stuff eden would need a server-side calling api for that though
Massukka
Massukka6mo ago
I will try that later.