Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

session option in sapper.middleware does not support Promise #740

Closed
hitochan777 opened this issue Jun 11, 2019 · 2 comments · Fixed by #743
Closed

session option in sapper.middleware does not support Promise #740

hitochan777 opened this issue Jun 11, 2019 · 2 comments · Fixed by #743

Comments

@hitochan777
Copy link
Contributor

I want to return promise in session option of sapper.middleware. But if I got an error saying
Failed to serialize session data: Cannot stringify arbitrary non-POJOs. It seems that the session option does not support promise. Is there any workaround?

polka()
  .use(
    sapper.middleware({
      session: async (req, res) => {
        const obj = await get_some_obj();
        return obj;
      }
    })
  )
@Conduitry
Copy link
Member

I don't think there's a technical reason for this. It looks like we should be able to add an await here. I don't know whether there'd be some other reason not to do this.

@Catsvilles
Copy link

I don't think there's a technical reason for this. It looks like we should be able to add an await here. I don't know whether there'd be some other reason not to do this.

In my case I would like to return a promise and pass it to the next component so I can do something like:
{#await promise}
//any kind of loading indicator
{:then res}

Am I'm implementing this wrong? I saw this kind of examples in Svelte's documentation, so I believed this is a good way to do a loader.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants