sidebase / nuxt-session

Nuxt session middleware to get a persistent session per app user, e.g., to store data across multiple requests. The nuxt session module provides the useSession() composable out of the box and sets up API endpoints to interact with your session to make working with sessions feel like a breeze.
https://sidebase.io/nuxt-session/
MIT License
188 stars 19 forks source link

Cannot use fs for session storage #84

Open ryoji-yamauchi-blc opened 1 year ago

ryoji-yamauchi-blc commented 1 year ago

Environment


Reproduction

https://github.com/ryoji-yamauchi-blc/nuxt-session-playground

npm install && npm run dev

 ERROR  [worker reload] [worker init] Cannot add property ignore, object is not extensible     5:01:26 PM

  at node_modules/unstorage/drivers/fs.mjs:20:17
  at .nuxt/dev/index.mjs:713:16
  at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Describe the bug

If fs is specified for session storage in nuxt.config.js, an error occurs.

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },
  modules: ["@sidebase/nuxt-session"],
  session: {
    session: {
      storageOptions: {
        driver: "fs",
        options: {
          base: "./data",
        },
      },
    },
  },
});

The cause is that the unstroage fs driver is updating the config returned by useRuntimeConfig. The config returned by useRuntimeConfig looks like Object.preventExtensions is set and cannot be updated. I could not read from the nuxt source code where it is set.

https://github.com/unjs/unstorage/blob/main/src/drivers/fs.ts#L32

Additional context

No response

Logs

No response

gbalcewicz commented 1 year ago

This also should be fixed on the unstorage side, the driver should not modify the options object: https://github.com/unjs/unstorage/issues/274