Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

505
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda