-
Notifications
You must be signed in to change notification settings - Fork 0
Improve auth session handling #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors authentication session handling by moving from a lazy-loading architecture to direct imports and implementing explicit startup auth initialization. The changes improve control over the authentication flow by separating session initialization from the AuthSession constructor and handling it in the App class.
Key Changes:
- Direct imports of auth modules (
AuthSession,CloudSyncService,AuthModal,UserMenu,Dashboard) instead of lazy-loading - New
initializeAuthState()method that handles startup token refresh with proper error handling and user feedback - Exposed helper methods in AuthSession (
hasRefreshToken(),clearSessionState()) to support the new initialization flow
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ui/App.ts | Adds direct auth module imports, implements initializeAuthState() for startup authentication with token refresh and error handling, shows login button by default |
| src/lib/auth/session.ts | Removes automatic token refresh from constructor, adds hasRefreshToken() and clearSessionState() helper methods for external session management |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| clearSessionState(): void { | ||
| this.clearSession(); | ||
| } |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The clearSessionState() method is a redundant wrapper around clearSession(). Since clearSession() is already a private method and clearSessionState() just calls it directly without any additional logic, this adds unnecessary indirection.
Consider either:
- Making
clearSession()public and removingclearSessionState() - Or adding meaningful documentation to explain why the wrapper exists (e.g., if it's part of a public API contract)
Currently, clearSessionState() doesn't add value over directly exposing clearSession().
| import { AuthSession } from '../lib/auth/session'; | ||
| import { CloudSyncService } from '../lib/cloud/sync'; | ||
| import { AuthModal } from './components/auth/AuthModal'; | ||
| import { UserMenu } from './components/auth/UserMenu'; | ||
| import { Dashboard } from './components/Dashboard'; | ||
|
|
||
| import { loadPdf, renderPageToCanvas, getPageCount } from '../lib/pdf/load'; |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The removed comments indicated these modules were previously intended for lazy loading to reduce initial bundle size. By importing them directly, these modules (AuthSession, CloudSyncService, AuthModal, UserMenu, Dashboard) are now included in the main bundle, which increases the initial bundle size.
Consider whether lazy loading is still desirable for these modules. If authentication and cloud features are not needed by all users immediately, code splitting could improve initial load performance. For example:
// Lazy load auth modules when needed
const { AuthSession } = await import('../lib/auth/session');
const { AuthModal } = await import('./components/auth/AuthModal');If the decision to remove lazy loading is intentional (e.g., for simpler code or because these features are always needed), consider updating documentation to reflect this architectural decision.
| import { AuthSession } from '../lib/auth/session'; | |
| import { CloudSyncService } from '../lib/cloud/sync'; | |
| import { AuthModal } from './components/auth/AuthModal'; | |
| import { UserMenu } from './components/auth/UserMenu'; | |
| import { Dashboard } from './components/Dashboard'; | |
| import { loadPdf, renderPageToCanvas, getPageCount } from '../lib/pdf/load'; |
Summary
Testing
Codex Task