The session store in src/hooks.js
is being populated by following these steps:
- Add some data to
event.locals
in the handle
function.
- Create a session object using
event.locals
in the getSession
function.
This session object can be accessed on the client as the session store and during server-side rendering (ssr) if you use the load
functions, but it is not accessible in endpoints.
However, what is available in the endpoint is the locals
variable that is passed to the getSession
function initially, so you can retrieve information from there.
export async function get({ locals }) {
// Add your code here
}
It's important to note that there is no synchronization between locals and the client-side session. If you add something to the session, it will not automatically be accessible in the endpoint. To manage this, you could consider adding new data to the cookie and parsing it in the handle
function.