{"id":49100,"library":"react-secure-storage","title":"React Secure Storage","description":"React Secure Storage (v1.3.2) is a wrapper around localStorage that encrypts stored data using a browser fingerprint and an optional user-provided secret key. It generates a unique encryption key per browser, ensuring data can only be decrypted in the same browser that encrypted it. Supports storing String, Object, Number, and Boolean without manual serialization. Uses a singleton pattern for in-memory caching. Works with React, Vite, and Next.js via environment variables. Lightweight and dependency-free. Compatible with TypeScript.","status":"active","version":"1.3.2","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/sushinpv/react-secure-storage","tags":["javascript","react secure local storage","react","local storage","typescript"],"install":[{"cmd":"npm install react-secure-storage","lang":"bash","label":"npm"},{"cmd":"yarn add react-secure-storage","lang":"bash","label":"yarn"},{"cmd":"pnpm add react-secure-storage","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Library exports a default export; named import will result in undefined.","wrong":"import { SecureStorage } from 'react-secure-storage'","symbol":"default","correct":"import SecureStorage from 'react-secure-storage'"},{"note":"In CommonJS, require returns the module, not the default export. Must access .default.","wrong":"const SecureStorage = require('react-secure-storage')","symbol":"SecureStorage","correct":"const SecureStorage = require('react-secure-storage').default"},{"note":"These methods are synchronous; no callback support.","wrong":"SecureStorage.setItem('key', value, callback)","symbol":"setItem / getItem / removeItem / clear","correct":"SecureStorage.setItem('key', value); const val = SecureStorage.getItem('key');"}],"quickstart":{"code":"import React from 'react';\nimport ReactDOM from 'react-dom';\nimport SecureStorage from 'react-secure-storage';\n\n// Optional: set hash key via environment variable (dotenv required for CRA)\n// REACT_APP_SECURE_LOCAL_STORAGE_HASH_KEY=mySecretKey\n// REACT_APP_SECURE_LOCAL_STORAGE_PREFIX=myApp_\n\n// Store data (supports string, object, number, boolean)\nSecureStorage.setItem('token', 'abc123');\nSecureStorage.setItem('user', { name: 'John', age: 30 });\nSecureStorage.setItem('count', 42);\nSecureStorage.setItem('isActive', true);\n\n// Retrieve data\nconst token = SecureStorage.getItem('token'); // 'abc123'\nconst user = SecureStorage.getItem('user');   // { name: 'John', age: 30 }\nconst count = SecureStorage.getItem('count'); // 42\nconst isActive = SecureStorage.getItem('isActive'); // true\n\n// Remove individual key\nSecureStorage.removeItem('token');\n\n// Clear all secure storage data\nSecureStorage.clear();\n\nfunction App() {\n  return <div>Check console</div>;\n}\n\nReactDOM.render(<App />, document.getElementById('root'));","lang":"javascript","description":"Basic usage: importing the library, setting and getting items of different types, and clearing storage."},"warnings":[{"fix":"This is by design; if cross-browser decryption is needed, use a static encryption key instead.","message":"Data stored with react-secure-storage can only be read by the same browser that wrote it; copying localStorage to another machine will not decrypt.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use import.meta.env.VITE_SECURE_LOCAL_STORAGE_HASH_KEY and ensure prefix is VITE_.","message":"In Vite, process.env is not available; you must define environment variables via import.meta.env and configure vite.config to expose them.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always set SECURE_LOCAL_STORAGE_HASH_KEY (with appropriate prefix) to a strong secret.","message":"If the hash key is not set via environment variable, a default key is used, reducing security.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to latest version and migrate data if necessary.","message":"Older versions (<1.3.0) used a different encryption algorithm; data encrypted with older versions may not be decrypted by >=1.3.0.","severity":"deprecated","affected_versions":"<1.3.0"}],"env_vars":null,"search_vec":"'around':11 'boolean':56 'browser':19,36,46 'cach':68 'compat':83 'data':16,38 'decrypt':42 'depend':81 'dependency-fre':80 'encrypt':14,33,48 'ensur':37 'environ':76 'fingerprint':20 'free':82 'generat':30 'in-memori':65 'javascript':86 'key':28,34 'lightweight':78 'local':89,92 'localstorag':12 'manual':58 'memori':67 'next.js':74 'number':54 'object':53 'option':23 'pattern':63 'per':35 'provid':26 'react':1,4,71,87,91 'secret':27 'secur':2,5,88 'serial':59 'singleton':62 'storag':3,6,90,93 'store':15,51 'string':52 'support':50 'typescript':85,94 'uniqu':32 'use':17,60 'user':25 'user-provid':24 'v1.3.2':7 'variabl':77 'via':75 'vite':72 'without':57 'work':69 'wrapper':10","created_at":"2026-06-07T17:00:03.370009+00:00","updated_at":"2026-06-07T17:00:03.370009+00:00","problems":[{"fix":"Use import SecureStorage from 'react-secure-storage'.","cause":"Using named import (import { SecureStorage } ...) instead of default import.","error":"TypeError: SecureStorage is not a function"},{"fix":"For Vite, use import.meta.env and define variables with VITE_ prefix.","cause":"Using in Vite or browser environment without process polyfill.","error":"Uncaught ReferenceError: process is not defined"},{"fix":"Check returned value before using: const val = SecureStorage.getItem('key'); if (val !== null) { ... }","cause":"getItem returns null for missing keys; calling methods on null.","error":"TypeError: Cannot read properties of null (reading 'toString')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/sushinpv/react-secure-storage#readme","github":"ssh://git@github.com/sushinpv/react-secure-storage","docs":null,"changelog":null,"pypi":null,"npm":"react-secure-storage","openapi_spec":null,"status_page":null,"smithery":null,"categories":["security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}