Closed Twitch0125 closed 1 year ago
Btw, I opened https://github.com/nuxt/nuxt.js/issues/15237 to see if this is a feature or a bug.
@BracketJohn Well, I'm stumped.
I'm trying to find a way to provide a useSessionStorage
function that works similar to useStorage
but with a separate unstorage instance. Initially I was trying to do that with a Nitro plugin, but there's very little documentation on what exactly you can do with those, and how you can add one from a nuxt module.
Looking at the source code for Nitro's useStorage
(which I believe is here https://github.com/unjs/nitro/blob/main/src/rollup/plugins/storage.ts), I feel like I'm missing something because surely we don't have to do this whole virtual module thing that nitro is doing, with a nuxt module...
@Twitch0125 I see, then we probably should switch to an approach where we provide: driver-name + options and then use the driver name to instantiate the right storage backend at runtime inside storage.ts
?
After getting some help from the nuxt discord, I was able to figure this out. nuxt-session now has its own unstorage instance completely separate from nitro's
Yay, this is great - thanks for keeping on pushing!
Can you by resolve the remaining test problems? Right now it's types:
Other than that: @valiafetisov will review the next week and then publish once merged (:
I was over complicating by creating a virtual module for the session config instead of using useRuntimeConfig.
I ended up adding a @ts-ignore to where I'm using the other virtual module. I tried creating a type for it with declare module '#session-driver'
but that didn't seem to be fixing it. But I'm still fairly noobish when it comes to typescript.
Can you please resolve conflicts? Then its ready to be merged!
@valiafetisov resolved!
Thanks @Twitch0125 for the contribution - it was awesome getting this in, I'll do the release shortly.
alright @Twitch0125 the fix is now available at @sidebase/nuxt-session@0.2.4, see the release notes here: https://github.com/sidebase/nuxt-session/releases/tag/0.2.4
Closes #8
Contributes to nuxt/nuxt.js#11734
Fixed by using Nitro's storage layer. The storageOptions were getting stored in the runtime config, but that looks like it does some kind of serializing. I had this config:
but was getting a "
fn
is not a function" error. When I checked the storageOptions instorage.ts
, thedriver
value was getting set to{}
.So now the equivalent config would look like this:
Also, in
storage.ts
, Typescript is yelling at me saying useStorage isn't exported from'#imports'
. I'm not sure where that actually gets exported if not from there.