Skip to content

Commit ca96815

Browse files
ExpressSessionManager
Fixes session item retrieval to preserve original data type Updates the Express session store to correctly return items that are not split into multiple parts. Previously, all session items were reassembled as strings upon retrieval, causing objects and other non-string types to be incorrectly converted. This change ensures that if an item is stored as a single entry, its original data type is preserved.
1 parent a0f45a5 commit ca96815

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/sessionManager/stores/expressStore.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe("ExpressStore", () => {
148148
await sessionManager.setSessionItem(StorageKeys.nonce, obj);
149149
expect(req.session![`${keyPrefix}nonce0`]).toEqual(obj);
150150
const value = await sessionManager.getSessionItem(StorageKeys.nonce);
151-
expect(value).toEqual("[object Object]"); // Because getSessionItem always reassembles as string
151+
expect(value).toEqual(obj); // Should return the original object
152152
});
153153
});
154154
});

lib/sessionManager/stores/expressStore.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ export class ExpressStore<V extends string = StorageKeys>
5353
if (this.req.session![`${baseKey}0`] === undefined) {
5454
return null;
5555
}
56+
57+
// if under settingConfig maxLength - return as-is
58+
if (this.req.session![`${baseKey}1`] === undefined) {
59+
return this.req.session![`${baseKey}0`];
60+
}
61+
62+
// Multiple items exist, concatenate them as strings (for split strings)
5663
let itemValue = "";
5764
let index = 0;
5865
let key = `${baseKey}${index}`;

0 commit comments

Comments
 (0)