Closed origranot closed 1 year ago
Start a new pull request in StackBlitz Codeflow.
Also tested it with the new release (0.20.0), same results 😢
The same thing happens to me, the console.log reads and executes it, but it doesn't set the cookie without a request or an action.
My guess is, onGet
is executed in server while cookie is browser specific. To workaround this, you can set header set-cookie
I think the possible fix would adjust this method https://github.com/BuilderIO/qwik/blob/f4e06e58b6fd57adb3dacb45d12dac97432ac2cc/packages/qwik-city/middleware/request-handler/cookie.ts#L117
to set set-cookie
in request header. However, I'm not sure, just my assumption
My guess is,
onGet
is executed in server while cookie is browser specific. To workaround this, you can set headerset-cookie
I think the possible fix would adjust this method
to set
set-cookie
in request header. However, I'm not sure, just my assumption
@ahnpnl At second look, it still has some weird issues. Some times it's not working well if I am trying to set multiple cookies.
Seems like cookie
is ignored when onGet
and components$
are used together.
It doesn't work with routeLoader$
either.
Set this as any route (index.ts):
export const onGet = async (act) => {
const { cookie, headers } = act
// cookie.set("a", "c", { path: "/" }) // not working
headers.set("Set-Cookie", "a=c") // working
}
export default component$(() => {
return (
<div>
...
Seems like
cookie
is ignored whenonGet
andcomponents$
are used together. It doesn't work withrouteLoader$
either.Set this as any route (index.ts):
export const onGet = async (act) => { const { cookie, headers } = act // cookie.set("a", "c", { path: "/" }) // not working headers.set("Set-Cookie", "a=c") // working } export default component$(() => { return ( <div> ...
It will work for the first cookie only.
There is a bug on VITE dev server. if you will try to build and serve qwik you will see it will work with cookie.set
Which component is affected?
Qwik City (routing)
Describe the bug
I want to be able to set cookie on page refresh, I am using access and refresh token for my authentication. My goal is to check on page refresh if the user don't have access token (expired or deleted) and have a valid refresh token, if this is the case I want to generate a new tokens from backend and set them as cookies.
My cookies is not being set on page refresh, only when I click attribute or use a redirect on other endpoint.
For the example I created this endpoint on my layout.tsx: The test cookie is not set on page refresh, it's only being set after clicking on attribute.
Reproduction
https://stackblitz.com/edit/qwik-starter-ak72zh?file=src/routes/layout.tsx
Steps to reproduce
System Info
Additional Information
No response