From f18882db1086c0106a33b24f8d604aab087e9b82 Mon Sep 17 00:00:00 2001 From: Alex Lohr Date: Mon, 29 Apr 2024 08:41:29 +0200 Subject: [PATCH] storage: default cookie options --- packages/storage/src/cookies.ts | 1 + packages/storage/src/tools.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/storage/src/cookies.ts b/packages/storage/src/cookies.ts index 40bcb269f..e4b5a0fdd 100644 --- a/packages/storage/src/cookies.ts +++ b/packages/storage/src/cookies.ts @@ -146,6 +146,7 @@ export const cookieStorage: StorageWithOptions = addWithOptionsMe return this.getLength(); }, }), + { path: "/" }, ); /** diff --git a/packages/storage/src/tools.ts b/packages/storage/src/tools.ts index a9fef1a34..604a75266 100644 --- a/packages/storage/src/tools.ts +++ b/packages/storage/src/tools.ts @@ -29,13 +29,14 @@ export const addWithOptionsMethod = < W extends AsyncStorage | Storage = S extends AsyncStorageWithOptions ? AsyncStorage : Storage, >( storage: S, + defaultOptions: Partial = {} ): S & { withOptions: (options: O) => W } => { storage.withOptions = (options: O): W => methodKeys.reduce( (wrapped: Partial, key: keyof S) => { if (typeof storage[key] === "function") { (wrapped as any)[key] = (...args: Parameters<(typeof storage)[typeof key]>) => { - args[storage[key].length - 1] = options; + args[storage[key].length - 1] = { ...defaultOptions, ...options }; return storage[key](...args); }; }