Persist user login state in Electron app#8
Conversation
Add persistent token storage for Electron desktop app to maintain user login state between application restarts. Previously, users had to log in every time they launched the app. Changes: - Add token storage IPC handlers in Electron main process - Expose token storage APIs via preload script - Create TokenStorage service to abstract storage (localStorage for web, electron-store for desktop) - Update AuthService to use async token storage - Update ApiClient to handle async token operations - Initialize auth state on app startup to restore login session - Update type definitions for new Electron APIs Technical details: - Tokens stored securely using electron-store in desktop app - Backward compatible with web app (continues using localStorage) - Async storage API ensures consistency across platforms
Pull Request Review: Persist User Login State in Electron AppOverviewThis PR adds persistent token storage for the Electron desktop app, allowing users to maintain their login state across application restarts. The implementation is well-structured and uses an abstraction layer to handle both Electron and web environments. ✅ Strengths
🔍 Code Quality Issues1. Race Condition in Token Refresh (Medium Priority)Location: The token refresh logic has a potential race condition. When Suggested Fix: Ensure // After successful refresh (around line 127)
this.isRefreshing = false
this.processQueue(null, access_token) // Process queue BEFORE setting isRefreshing to false2. Missing Null Checks in TypeScript (Low Priority)Location: While the code handles null gracefully at runtime, the type definitions could be more defensive: async getAccessToken(): Promise<string | null> {
if (this.isElectron && window.electronAPI) {
return await window.electronAPI.getAccessToken()
}
return localStorage.getItem('access_token')
}The check 3. Initialization Timing Issue (Medium Priority)Location: The app shows a loading spinner during auth initialization, which is good. However, if useEffect(() => {
loadUser()
.catch((error) => {
console.error('Failed to load user:', error)
// Still set initialized to allow app to render
})
.finally(() => {
setIsInitialized(true)
})
}, [loadUser])🔒 Security Considerations1. Token Storage Security (Info)
Current implementation is acceptable for this application's threat model, but worth noting for future consideration. 2. Token Exposure in IPC (Low Risk)Location: Tokens are passed through IPC channels. This is generally safe since IPC in Electron is isolated, but ensure:
🐛 Potential Bugs1.
|
Add persistent token storage for Electron desktop app to maintain user login state between application restarts. Previously, users had to log in every time they launched the app.
Changes:
Technical details: