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 of isAuthenticated exist, not global singelon)
checkAuthentication() makes API call to /api/user/status/ on every invocation
- Defines
onMounted(() => checkAuthentication()) (duplicate)
- Custom event system:
auth-state-changed event with listener setup
2. Auth State Change Mechanism
Event-Based System:
notifyAuthStateChanged() dispatches auth-state-changed window event
onAuthStateChanged() listens event and will call checkAuthentication() to update isAuthenticated
3. Identified Issues & Inefficiencies
- No shared state: Each
useAuth() call creates separate isAuthenticated
- Complicate event system: use event to notify
isAuthenticated change, but views still need to call checkAuthentication to get the updated value
5. Solutions
- implment a global
isAuthenticated in useAuth.js(views will not have copies of isAuthenticated)
- auth related function in useAuth.js update isAuthenticated(only functions in useAuth.js could modify isAuthenticated. for all views/components,
isAuthenticated is read-only )
- remove custom event and its event stack(
notifyAuthStateChanged() and onAuthStateChanged())
- for normal views/components, remove watcher business that acts when
isAuthenticated changes from false to true(keep from true to false) but keep checkAuthentication on Mount(in case session expire)
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)
isAuthenticated(multiple instances ofisAuthenticatedexist, not global singelon)checkAuthentication()makes API call to/api/user/status/on every invocationonMounted(() => checkAuthentication())(duplicate)auth-state-changedevent with listener setup2. Auth State Change Mechanism
Event-Based System:
notifyAuthStateChanged()dispatchesauth-state-changedwindow eventonAuthStateChanged()listens event and will callcheckAuthentication()to updateisAuthenticated3. Identified Issues & Inefficiencies
useAuth()call creates separateisAuthenticatedisAuthenticatedchange, but views still need to callcheckAuthenticationto get the updated value5. Solutions
isAuthenticatedin useAuth.js(views will not have copies ofisAuthenticated)isAuthenticatedis read-only )notifyAuthStateChanged()andonAuthStateChanged())isAuthenticatedchanges from false to true(keep from true to false) but keepcheckAuthenticationon Mount(in case session expire)