solid-primitives icon indicating copy to clipboard operation
solid-primitives copied to clipboard

[storage] `cookieStorage`'s `maxAge` option doesn't work

Open yume-chan opened this issue 2 years ago • 3 comments

Describe the bug

Create a persisted signal using cookieStorage and passing the maxAge option, but the created cookie is a session cookie.

In the linked StackBlitz project, click "Open in New Tab" button at top-right corner. Looks like it can't set cookies from an iframe.

  const [maxAge, setMaxAge] = makePersisted(createSignal('initial'), {
    name: 'maxAge',
    storage: cookieStorage,
    storageOptions: { path: '/', maxAge: 60 * 60 * 24 * 7 },
  });
  const [expires, setExpires] = makePersisted(createSignal('initial'), {
    name: 'expires',
    storage: cookieStorage,
    storageOptions: {
      path: '/',
      expires: new Date(Date.now() + 60 * 60 * 24 * 7 * 1000),
    },
  });

  createEffect(() => {
    setMaxAge('hello');
    setExpires('hello');
  });

image

Minimal Reproduction Link

https://stackblitz.com/edit/github-n4ho5j-nffe5j?file=src%2Froutes%2Findex.tsx

yume-chan avatar Oct 20 '23 04:10 yume-chan

I confirm this error

sh1man999 avatar Nov 21 '23 13:11 sh1man999

The problem is serializeCookieOptions doesn't convert maxAge to max-age

apatrida avatar Apr 29 '24 04:04 apatrida

Thanks, will fix.

atk avatar Apr 29 '24 06:04 atk