Freelancers October 24, 2020

Will pay a Svelte/Sapper dev to help me resolve this issue

Jason Creviston @thecrev

Looking for an experienced svelte dev - specifically how session state should be handled in Sapper. So the app knows when someone is logged in. I must not be doing session state correctly in my web app.

Normal authentication/session is working - although maybe the config needs tweaked, and is contributing to my current issue. But when I visit a certain page, it's like the app doesn't know the user is logged in anymore.

I've fought this enough, and am looking for some help. We can hop on a Teams call or whatever to share my screen. Or if you'd like to recommend someone, that's good too. Else I suppose I'll try fiverr or guru or wherever freelance devs hangout these days.

I'm based in the US East timezone. [email protected]


    1. 1

      Thanks! Yeah I'm using mongo for the session store.

  1. 1

    This probably isn’t the most helpful comment, but just a hint:
    If you’re not using express-session, session-file-store or utilising the ‘sapper.middleware()’ function properly in your server.js file, you’re probably doing something wrong. Sorry if you know this all already!

    1. 1

      Thank you. I am using express-session, mongodb-session or whatever, and sapper middleware.

      One thing that I didn't mention - and maybe makes a difference - is that I'm using a query parameter in my subscribe link.

      So, if I am logged in, and go to from the menu - the app knows I'm logged in and everything works.

      If I am NOT logged into my app, and click a 'subscribe' link on a test site to[email protected] the app behaves as normal - it recognizes I'm not logged in, redirects me to the index page and displays the login form, I login, then it redirects me back to the subscribe link above, asks me to confirm the subscription, and everything is golden.

      However, if I'm already logged into my app when I click on the subscribe link from my test site, the code in subscribe.svelte doesn't think I'm logged in, and redirects me to the index page which of course displays my inbox since I actually am logged in.

      So at that point the url in the address bar is[email protected]

      If I now remove from the address bar and hit the return button, everything works as expected.

      It's weird.

      I've used subscribe/?sub= and subscribe?sub= because I was getting some weird results if I didn't have the /

      1. 1

        Hmm yeah, that is weird. Changes to the session on the server aren't always automatically reflected on the client. So maybe you're not using the client side session svelte store (from the stores() function exported from '@sapper/app')?

        Backend: req.session.user = true;
        Fronted : $session.user = true;

        That's all I can think of, off the top of my head

        1. 1

          Thank you again. I don't set session.authenticated on the server side, but I thought I was setting it on the client side - after the user logs in. Does this set $session.authenticated properly?

          const { session } = stores()
          const api = process.env.API_URL

          async function login(event) {
          const data = {

          const res = await fetch(${api}/v0/auth/login, {
          method: 'POST',
          body: JSON.stringify(data)
          .then(response => {
          return response.json()

          if (res.success === true) {
          $session.authenticated = true

Recommended Posts