Sapper: session option in sapper.middleware does not support Promise

Created on 11 Jun 2019  路  2Comments  路  Source: sveltejs/sapper

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;
      }
    })
  )
enhancement

Most helpful comment

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.

All 2 comments

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

UnwrittenFun picture UnwrittenFun  路  4Comments

SARFEX picture SARFEX  路  3Comments

Snugug picture Snugug  路  4Comments

milosdjakovic picture milosdjakovic  路  3Comments

Rich-Harris picture Rich-Harris  路  3Comments