Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

498
Views
How to access sveltekit session in endpoint?

How do you access a session in an endpoint in sveltekit? I've tried this but no luck:

import { get } from 'svelte/store';    
import { getStores} from "$app/stores";

function getUser() { // <- call this at component initialization
  const { session } = getStores();
 
  return {
    current: () => get(session).user
  }
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The session store only works inside svelte components, (it uses context under the hood) this provides isolation between users.

You can import the getSession from src/hooks.js and pass the event to reuse the logic that extracts session data from the request.

about 4 years ago · Juan Pablo Isaza Report

0

The session store is being populated in src/hooks.js, the normal flow to do so is

  1. in handle, add some data to event.locals.
  2. in getSession, use event.locals to create a session object.

This session object is available in the client as the session store, and on during ssr if you use the load functions, but it is not available in endpoints.

What is available though in the endpoint is the locals variable, that is originally passed to the getSession function, so you can read that one.

export async function get({ locals }) {
  // code goes here
}

Just be aware that this means there is no synchronization between locals and the client side session, if you add something to the session it will not be available to the endpoint. To handle this you would have to for example add new data to the cookie and parse this in the handle function.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!