- Replace `electron-store` with OS-level encrypted storage for secure token, userId, and language management in `LocalSystem` and `keyManager`. - Add `init-user` IPC handler to initialize user data and manage encryption keys. - Update login process to handle encrypted storage saving with fallback for macOS issues. - Add offline warning component to `login/page.tsx` to handle first-time sync requirements. - Remove `electron-store` and associated dependencies from `package.json` and `package-lock.json`.
38 lines
1.7 KiB
TypeScript
38 lines
1.7 KiB
TypeScript
const { contextBridge, ipcRenderer } = require('electron');
|
|
|
|
/**
|
|
* Exposer des APIs sécurisées au renderer process
|
|
* Utilise invoke() générique pour tous les appels IPC
|
|
*/
|
|
contextBridge.exposeInMainWorld('electron', {
|
|
// Platform info
|
|
platform: process.platform,
|
|
|
|
// Generic invoke method - use this for all IPC calls
|
|
invoke: (channel: string, ...args: any[]) => ipcRenderer.invoke(channel, ...args),
|
|
|
|
// Token management (shortcuts for convenience)
|
|
getToken: () => ipcRenderer.invoke('get-token'),
|
|
setToken: (token: string) => ipcRenderer.invoke('set-token', token),
|
|
removeToken: () => ipcRenderer.invoke('remove-token'),
|
|
|
|
// Language management (shortcuts for convenience)
|
|
getLang: () => ipcRenderer.invoke('get-lang'),
|
|
setLang: (lang: 'fr' | 'en') => ipcRenderer.invoke('set-lang', lang),
|
|
|
|
// Auth events (use send for one-way communication)
|
|
loginSuccess: (token: string) => ipcRenderer.send('login-success', token),
|
|
logout: () => ipcRenderer.send('logout'),
|
|
|
|
// User initialization (after getting user info from server)
|
|
initUser: (userId: string) => ipcRenderer.invoke('init-user', userId),
|
|
|
|
// Encryption key management (shortcuts for convenience)
|
|
generateEncryptionKey: (userId: string) => ipcRenderer.invoke('generate-encryption-key', userId),
|
|
getUserEncryptionKey: (userId: string) => ipcRenderer.invoke('get-user-encryption-key', userId),
|
|
setUserEncryptionKey: (userId: string, encryptionKey: string) => ipcRenderer.invoke('set-user-encryption-key', userId, encryptionKey),
|
|
|
|
// Database initialization (shortcut for convenience)
|
|
dbInitialize: (userId: string, encryptionKey: string) => ipcRenderer.invoke('db-initialize', userId, encryptionKey),
|
|
});
|