knpwrs
knpwrs
SSolidJS
Created by knpwrs on 8/19/2023 in #support
Setting cookies (or headers in general) from `createServerData$`
I came across this post: https://discordapp.com/channels/722131463138705510/1057288732555878530/1057384833497714688 Which lead me to do the following: Inside routeData()
const successData = createServerData$(async (_, { request }) => {
const session = await getSession(request);

return json(session.get('success') ?? '', {
headers: { 'Set-Cookie': await commitSession(session) },
});
});

return { user, successData };
const successData = createServerData$(async (_, { request }) => {
const session = await getSession(request);

return json(session.get('success') ?? '', {
headers: { 'Set-Cookie': await commitSession(session) },
});
});

return { user, successData };
And then inside the component:
const [success] = createResource(successData, (s) => s.json());
const [success] = createResource(successData, (s) => s.json());
And then I can use it in my tsx!
<main>{success()}</main>
<main>{success()}</main>
3 replies