feat: replace demo storage instances with secure storage implementations across i18n and storage features
This commit is contained in:
@@ -32,36 +32,36 @@ This package provides a unified, Promise-based interface for interacting with br
|
||||
|
||||
### 1. Secure Local Storage (Tokens, Profile)
|
||||
|
||||
Use `demoSecureStorage` (or your app's configured instance) for small payloads. If the key is in `ENCRYPTED_KEYS`, it will be encrypted at rest.
|
||||
Use `secureStorage` (or your app's configured instance) for small payloads. If the key is in `ENCRYPTED_KEYS`, it will be encrypted at rest.
|
||||
|
||||
```typescript
|
||||
import { demoSecureStorage, StorageKey } from '@repo/core-storage';
|
||||
import { secureStorage, StorageKey } from '@repo/core-storage';
|
||||
import type { UserProfile } from '@/types';
|
||||
|
||||
// CREATE / UPDATE
|
||||
// If StorageKey.USER_PROFILE is in ENCRYPTED_KEYS, this is AES-encrypted automatically.
|
||||
await demoSecureStorage.setItem(StorageKey.USER_PROFILE, {
|
||||
await secureStorage.setItem(StorageKey.USER_PROFILE, {
|
||||
id: 1,
|
||||
name: 'Firman',
|
||||
role: 'admin'
|
||||
});
|
||||
|
||||
// READ
|
||||
const profile = await demoSecureStorage.getItem<UserProfile>(StorageKey.USER_PROFILE);
|
||||
const profile = await secureStorage.getItem<UserProfile>(StorageKey.USER_PROFILE);
|
||||
if (profile) {
|
||||
console.log('Welcome back,', profile.name);
|
||||
}
|
||||
|
||||
// DELETE
|
||||
await demoSecureStorage.removeItem(StorageKey.USER_PROFILE);
|
||||
await secureStorage.removeItem(StorageKey.USER_PROFILE);
|
||||
```
|
||||
|
||||
### 2. IndexedDB (Offline Data, Large Payloads)
|
||||
|
||||
Use the pre-configured `demoIndexedDB` (or instantiate your own) for large, asynchronous data. It uses the exact same API and encryption pipeline.
|
||||
Use the pre-configured `secureIndexedDB` (or instantiate your own) for large, asynchronous data. It uses the exact same API and encryption pipeline.
|
||||
|
||||
```typescript
|
||||
import { demoIndexedDB } from '@repo/core-storage';
|
||||
import { secureIndexedDB } from '@repo/core-storage';
|
||||
|
||||
interface DraftData {
|
||||
id: string;
|
||||
@@ -70,14 +70,14 @@ interface DraftData {
|
||||
}
|
||||
|
||||
// Save a large draft offline
|
||||
await demoIndexedDB.setItem('offline_draft_123', {
|
||||
await secureIndexedDB.setItem('offline_draft_123', {
|
||||
id: '123',
|
||||
content: 'Huge text content...',
|
||||
lastModified: Date.now()
|
||||
});
|
||||
|
||||
// Retrieve the draft
|
||||
const draft = await demoIndexedDB.getItem<DraftData>('offline_draft_123');
|
||||
const draft = await secureIndexedDB.getItem<DraftData>('offline_draft_123');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user