@@ -24,86 +24,135 @@ function App() {
2424 } , [ ] ) ;
2525
2626 async function initialize ( ) {
27+ const initId = Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
28+ console . log ( `π [initialize:${ initId } ] START` ) ;
29+
2730 // Check if vault exists
2831 const exists = await vaultExists ( ) ;
32+ console . log ( `π [initialize:${ initId } ] Vault exists: ${ exists } ` ) ;
2933
3034 if ( ! exists ) {
35+ console . log ( `π [initialize:${ initId } ] No vault, going to setup` ) ;
3136 setScreen ( 'setup' ) ;
3237 return ;
3338 }
3439
3540 // Check if already unlocked
3641 const session = await getSession ( ) ;
42+ console . log ( `π [initialize:${ initId } ] Session unlocked: ${ session . unlocked } ` ) ;
43+
3744 if ( session . unlocked ) {
3845 // Try to pull cached vault data from background (no password prompt)
3946 try {
47+ console . log ( `π [initialize:${ initId } ] Requesting cached vault from background...` ) ;
4048 const resp = await chrome . runtime . sendMessage ( { type : 'GET_VAULT_DATA' } ) ;
49+ console . log ( `π [initialize:${ initId } ] Background response:` , resp ? 'got response' : 'null' ) ;
50+
4151 if ( resp ?. vault ) {
42- setVaultData ( resp . vault as VaultData ) ;
52+ const vault = resp . vault as VaultData ;
53+ console . log ( `π [initialize:${ initId } ] Cached vault - keys: ${ vault . keys ?. length } , groups: ${ vault . groups ?. length } ` ) ;
54+ console . log ( `π [initialize:${ initId } ] Cached group IDs:` , vault . groups ?. map ( g => ( { id : g . id , name : g . name } ) ) ) ;
55+ setVaultData ( vault ) ;
4356 setScreen ( 'dashboard' ) ;
4457 return ;
58+ } else {
59+ console . log ( `π [initialize:${ initId } ] No vault in response, fallback to login` ) ;
4560 }
4661 } catch ( e ) {
47- console . warn ( ' Could not retrieve cached vault, fallback to login' , e ) ;
62+ console . warn ( `π [initialize: ${ initId } ] Could not retrieve cached vault, fallback to login` , e ) ;
4863 }
4964 }
65+ console . log ( `π [initialize:${ initId } ] Going to login screen` ) ;
5066 setScreen ( 'login' ) ;
5167 }
5268
5369 async function handleSetup ( password : string ) {
70+ const setupId = Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
71+ console . log ( `π¬ [handleSetup:${ setupId } ] START` ) ;
72+
5473 try {
74+ console . log ( `π¬ [handleSetup:${ setupId } ] Creating vault...` ) ;
5575 await createVault ( password ) ;
76+
77+ console . log ( `π¬ [handleSetup:${ setupId } ] Setting master password in state` ) ;
5678 setMasterPassword ( password ) ;
79+
5780 const emptyVault : VaultData = { keys : [ ] , groups : [ ] } ;
81+ console . log ( `π¬ [handleSetup:${ setupId } ] Setting empty vault in state` ) ;
5882 setVaultData ( emptyVault ) ;
83+
84+ console . log ( `π¬ [handleSetup:${ setupId } ] Marking vault unlocked` ) ;
5985 await markVaultUnlocked ( ) ;
86+
87+ console . log ( `π¬ [handleSetup:${ setupId } ] Caching in background...` ) ;
6088 await cacheVaultInBackground ( emptyVault , password ) ;
89+
90+ console . log ( `π¬ [handleSetup:${ setupId } ] SUCCESS - going to onboarding` ) ;
6191 // New vault = needs onboarding
6292 setScreen ( 'onboarding' ) ;
6393 } catch ( error ) {
64- console . error ( 'Setup failed:' , error ) ;
94+ console . error ( `π¬ [handleSetup: ${ setupId } ] FAILED:` , error ) ;
6595 alert ( 'Failed to create vault. Please try again.' ) ;
6696 }
6797 }
6898
6999 async function handleLogin ( password : string ) {
100+ const loginId = Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
101+ console . log ( `π [handleLogin:${ loginId } ] START` ) ;
102+
70103 try {
104+ console . log ( `π [handleLogin:${ loginId } ] Calling unlockVault...` ) ;
71105 const data = await unlockVault ( password ) ;
72106 if ( ! data ) {
107+ console . log ( `π [handleLogin:${ loginId } ] unlockVault returned null (wrong password)` ) ;
73108 alert ( 'Incorrect password' ) ;
74109 return ;
75110 }
76111
112+ console . log ( `π [handleLogin:${ loginId } ] unlockVault returned - keys: ${ data . keys . length } , groups: ${ data . groups . length } ` ) ;
113+ console . log ( `π [handleLogin:${ loginId } ] Group IDs from storage:` , data . groups . map ( g => ( { id : g . id , name : g . name } ) ) ) ;
114+
77115 setMasterPassword ( password ) ;
78116 setVaultData ( data ) ;
79117 await markVaultUnlocked ( ) ;
80118
81119 // Cache vault in background script
120+ console . log ( `π [handleLogin:${ loginId } ] Caching in background...` ) ;
82121 await cacheVaultInBackground ( data , password ) ;
83122
123+ console . log ( `π [handleLogin:${ loginId } ] SUCCESS - going to dashboard` ) ;
84124 setScreen ( 'dashboard' ) ;
85125 } catch ( error ) {
86- console . error ( 'Login failed:' , error ) ;
126+ console . error ( `π [handleLogin: ${ loginId } ] FAILED:` , error ) ;
87127 alert ( 'Failed to unlock vault. Please try again.' ) ;
88128 }
89129 }
90130
91131 async function cacheVaultInBackground ( _data : VaultData , _password : string ) {
132+ const cacheId = Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
133+ console . log ( `π€ [cacheVaultInBackground:${ cacheId } ] START - Sending CACHE_VAULT to background` ) ;
134+ console . log ( `π€ [cacheVaultInBackground:${ cacheId } ] Current local state - keys: ${ _data . keys . length } , groups: ${ _data . groups . length } ` ) ;
135+ console . log ( `π€ [cacheVaultInBackground:${ cacheId } ] Group IDs in local state:` , _data . groups . map ( g => ( { id : g . id , name : g . name } ) ) ) ;
136+
92137 try {
93- await chrome . runtime . sendMessage ( {
138+ const response = await chrome . runtime . sendMessage ( {
94139 type : 'CACHE_VAULT' ,
95140 payload : { masterPassword : _password } ,
96141 } ) ;
142+ console . log ( `π€ [cacheVaultInBackground:${ cacheId } ] Response from background:` , response ) ;
97143 } catch ( err ) {
98- console . error ( 'Failed to cache vault in background' , err ) ;
144+ console . error ( `π€ [cacheVaultInBackground: ${ cacheId } ] FAILED:` , err ) ;
99145 }
100146 }
101147
102148 async function handleLock ( ) {
149+ console . log ( `π [handleLock] Locking vault...` ) ;
150+ console . log ( `π [handleLock] Current state before lock - keys: ${ vaultData ?. keys ?. length } , groups: ${ vaultData ?. groups ?. length } ` ) ;
103151 await markVaultLocked ( ) ;
104152 setVaultData ( null ) ;
105153 setMasterPassword ( '' ) ;
106154 setScreen ( 'login' ) ;
155+ console . log ( `π [handleLock] Vault locked, going to login` ) ;
107156 }
108157
109158 function handleCompose ( ) {
@@ -158,18 +207,30 @@ function App() {
158207 }
159208
160209 async function handleVaultUpdate ( updatedVault : VaultData ) {
210+ const updateId = Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
211+ console . log ( `π [handleVaultUpdate:${ updateId } ] START` ) ;
212+ console . log ( `π [handleVaultUpdate:${ updateId } ] Incoming vault - keys: ${ updatedVault . keys . length } , groups: ${ updatedVault . groups . length } ` ) ;
213+ console . log ( `π [handleVaultUpdate:${ updateId } ] Group IDs:` , updatedVault . groups . map ( g => ( { id : g . id , name : g . name } ) ) ) ;
214+ console . log ( `π [handleVaultUpdate:${ updateId } ] Current state - keys: ${ vaultData ?. keys ?. length } , groups: ${ vaultData ?. groups ?. length } ` ) ;
215+
161216 try {
162217 // Save to storage FIRST before updating UI state
218+ console . log ( `π [handleVaultUpdate:${ updateId } ] Step 1: Calling saveVault...` ) ;
163219 const { saveVault } = await import ( '@/storage/vault' ) ;
164220 await saveVault ( updatedVault , masterPassword ) ;
221+ console . log ( `π [handleVaultUpdate:${ updateId } ] saveVault completed successfully` ) ;
165222
166223 // Only update state after successful save
224+ console . log ( `π [handleVaultUpdate:${ updateId } ] Step 2: Updating React state...` ) ;
167225 setVaultData ( updatedVault ) ;
168226
169227 // Update background cache
228+ console . log ( `π [handleVaultUpdate:${ updateId } ] Step 3: Updating background cache...` ) ;
170229 await cacheVaultInBackground ( updatedVault , masterPassword ) ;
230+
231+ console . log ( `π [handleVaultUpdate:${ updateId } ] SUCCESS - all steps completed` ) ;
171232 } catch ( error ) {
172- console . error ( 'Failed to save vault update:' , error ) ;
233+ console . error ( `π [handleVaultUpdate: ${ updateId } ] FAILED:` , error ) ;
173234 alert ( 'β οΈ Failed to save changes. Please try again. If this persists, export your vault backup from Settings.' ) ;
174235 // Don't update UI state if save failed - keep showing old data
175236 }
0 commit comments