-
Notifications
You must be signed in to change notification settings - Fork 0
Labels
enhancementNew feature or requestNew feature or request
Description
frontend vue3 codes are under frontend/ directory.
Auth State Management Investigation
Current Architecture
Key Findings
1. Authentication State Management Issues
useAuth.js (src/composables/useAuth.js:35-214)
- will return a copy of
isAuthenticated(multiple instances ofisAuthenticatedexist, not global singelon) checkAuthentication()makes API call to/api/user/status/on every invocation- Defines
onMounted(() => checkAuthentication())(duplicate) - Custom event system:
auth-state-changedevent with listener setup
2. Auth State Change Mechanism
Event-Based System:
notifyAuthStateChanged()dispatchesauth-state-changedwindow eventonAuthStateChanged()listens event and will callcheckAuthentication()to updateisAuthenticated
3. Identified Issues & Inefficiencies
- No shared state: Each
useAuth()call creates separateisAuthenticated - Complicate event system: use event to notify
isAuthenticatedchange, but views still need to callcheckAuthenticationto get the updated value
5. Solutions
- implment a global
isAuthenticatedin useAuth.js(views will not have copies ofisAuthenticated) - auth related function in useAuth.js update isAuthenticated(only functions in useAuth.js could modify isAuthenticated. for all views/components,
isAuthenticatedis read-only ) - remove custom event and its event stack(
notifyAuthStateChanged()andonAuthStateChanged()) - for normal views/components, remove watcher business that acts when
isAuthenticatedchanges from false to true(keep from true to false) but keepcheckAuthenticationon Mount(in case session expire)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
In Progress