-
-
Notifications
You must be signed in to change notification settings - Fork 20
fix: allow unstorage drivers other than 'memory' #7
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Twitch0125 👋
Awesome PR, thanks for the contribution and the clear description ❤️
I want to get this merged, but we need to change some points first. Mainly, this is about allowing the configuration of nuxt-session
not to clash with the main-app storage configuration.
The requested changed will also resolve the typescript issues as we stop relying on the useStorage
composable of nuxt inside our storage.ts
Btw, I opened nuxt/nuxt#15237 to see if this is a feature or a bug. |
@BracketJohn Well, I'm stumped. Looking at the source code for Nitro's |
@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 |
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. |
src/module.ts
Outdated
|
||
export type SameSiteOptions = 'lax' | 'strict' | 'none' | ||
export type SupportedSessionApiMethods = 'patch' | 'delete' | 'get' | 'post' | ||
|
||
interface StorageOptions { | ||
driver: BuiltinDriverName, | ||
options: object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object can be almost everything in javascript, eg array is also an object. Is it possible to specify it further or even extend this type based on the driver
name? I assume that every driver has its own set of options, or are they of the same type?
I think something like mapped types might help here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found each of the drivers option types from unstorage, so its using those now.
Co-authored-by: valia fetisov <[email protected]>
Can you please resolve conflicts? Then its ready to be merged! |
@valiafetisov resolved! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ❤️ Here one more proposal from me, but please treat it as non-blocking.
Thanks for all the hard work and patience (:
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/[email protected], see the release notes here: https://github.com/sidebase/nuxt-session/releases/tag/0.2.4 |
Closes #8
Contributes to nuxt/nuxt#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 in
storage.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.