pixelmund / svelte-kit-cookie-session

⚒️ Encrypted "stateless" cookie sessions for SvelteKit
MIT License
184 stars 12 forks source link

Hook for setting initial session state #47

Closed elliott-with-the-longest-name-on-github closed 1 year ago

elliott-with-the-longest-name-on-github commented 1 year ago

It would be super cool to have a hook in handleSession for setting the initial session state:

const generateInitialState = () => {
  return {
    something: 'default'
  }
}

export const handle = handleSession({ 
  init: generateInitialState
});

This would enable us to make sure the shape of the object we're storing in sessiondata is always what we expect (and not "undefined")

pixelmund commented 1 year ago

Hey you can now set the initial session state with version 3.3.0

export const handle = handleSession({
    init: (event) => ({
        views: 0
    })
});
elliott-with-the-longest-name-on-github commented 1 year ago

❤️