2
votes

I'm trying to make a SSR-app using Sapper+Svelte which utilizes GraphQL API. I've checked the project https://github.com/antony/sapper-authentication-demo and read official docs, but I can't make it work and also I'm confused with the way it made. 1) as I can see the Sapper server app uses cookies to authenticate on API. Which I find weird because I expect it to use JWT access keys for it 2) Also regardless how I try to save information received from server into session and then later reach it out in Svelte templates - it doesn't show anything in the session.

I'm kinda new in Javascript but have big experience with web development and I understand the way cookies/sessions work, but for some reason I don't get how it shall work in experess/polka and why I can't save anything into session and then read it.

Any suggestions or help will be greatly appreciated

1

1 Answers

0
votes

since it is SSR then you need to pass the token server side too, else you will not be able to use the token.

so in server.js after receiving the cookie you need to store it as a session then also use the sapper middleware where you will return the session as a token

sapper.middleware({
    session: (req, res) => {
        return ({
            token: req.session.token
        })
    }