Replace Local Storage with Session Storage for Message Persistence
#1 opened on Feb 9, 2025
Repository metrics
- Stars
- (1 star)
- PR merge metrics
- (PR metrics pending)
Description
Description:
Currently, the this Chat App stores messages in Local Storage, which saves messages only on the same browser. If the same user logs in from a different browser or device, the previous messages do not appear.
To improve temporary message persistence, we should replace Local Storage with Session Storage, allowing messages to persist during a session but be deleted once the session ends or the user logs out.
🔹Feature Requirements:
✅ Replace Local Storage with Session Storage to ensure messages are stored only during an active session. ✅ Retain messages when the user navigates within the app. ✅ Automatically clear messages when the user closes/reloads the browser. ✅ Provide a manual delete option for users to remove messages within a session. ✅ Ensure end-to-end encryption remains intact (if applicable).
🔹Current Behavior (Local Storage):
- Stores messages persistently in the browser.
- Messages do not sync when the same user logs in from a different browser/device.
🔹Proposed Behavior (Session Storage):
- Messages are temporarily stored until the user closes the session.
- Messages are cleared automatically after a session ends.
- Improves security by ensuring messages are not permanently stored.
🔹Tech Stack:
- JavaScript (sessionStorage API)
- React
🔹Possible Implementation Steps:
- Modify message storage logic to use sessionStorage.setItem() instead of localStorage.setItem().
- Retrieve messages from sessionStorage on app load using sessionStorage.getItem().
- Implement a delete feature using sessionStorage.removeItem() to allow users to clear messages manually.
- Test the behavior to ensure messages persist correctly during a session and are removed after closing the browser.
🔹Labels:
- enhancement
💡 Feel free to ask any questions or seek clarifications in the comments! Looking forward to your contributions. 🚀