[PR #1842] [MERGED] Fix Incorrect JSON Handling in secondaryStorage.get Documentation #4024

Closed
opened 2026-03-13 11:28:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/1842
Author: @meisolated
Created: 3/16/2025
Status: Merged
Merged: 3/16/2025
Merged by: @Bekacru

Base: mainHead: patch-1


📝 Commits (2)

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 docs/content/docs/concepts/database.mdx (+1 -1)

📄 Description

This PR updates the database.mdx documentation file to fix an issue caused by incorrect handling of JSON data in secondaryStorage.get.

Issue

The current documentation suggests using:

return value ? JSON.stringify(value) : null;

This results in the stored JSON string being re-stringified, causing an issue when parsing it later. Specifically, when safeJSONParse is used, it returns a string instead of an array, leading to:

TypeError: list.filter is not a function.

Fix

The correct approach is to return the value directly instead of wrapping it in JSON.stringify(value). The updated code should be:

return value ? value : null;

Changes

  • Updated database.mdx to reflect the correct implementation.
  • Added a note explaining that JSON.stringify should not be used in get, as Redis stores values as strings by default.

Impact

This fix ensures that retrieved JSON data remains correctly formatted and prevents runtime errors related to .filter being called on a string instead of an array.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/1842 **Author:** [@meisolated](https://github.com/meisolated) **Created:** 3/16/2025 **Status:** ✅ Merged **Merged:** 3/16/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `patch-1` --- ### 📝 Commits (2) - [`332b9aa`](https://github.com/better-auth/better-auth/commit/332b9aa807dea71212a8e7fd80dd5094c3c12dc2) Update database.mdx - [`eeacc59`](https://github.com/better-auth/better-auth/commit/eeacc59473c6744ede2ac85e06dfb30b22df8491) Update database.mdx ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/concepts/database.mdx` (+1 -1) </details> ### 📄 Description This PR updates the `database.mdx` documentation file to fix an issue caused by incorrect handling of JSON data in `secondaryStorage.get`. #### **Issue** The current documentation suggests using: ```js return value ? JSON.stringify(value) : null; ``` This results in the stored JSON string being re-stringified, causing an issue when parsing it later. Specifically, when `safeJSONParse` is used, it returns a string instead of an array, leading to: ``` TypeError: list.filter is not a function. ``` #### **Fix** The correct approach is to return the value directly instead of wrapping it in `JSON.stringify(value)`. The updated code should be: ```js return value ? value : null; ``` #### **Changes** - Updated `database.mdx` to reflect the correct implementation. - Added a note explaining that `JSON.stringify` should not be used in `get`, as Redis stores values as strings by default. #### **Impact** This fix ensures that retrieved JSON data remains correctly formatted and prevents runtime errors related to `.filter` being called on a string instead of an array. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 11:28:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#4024