88 unlockWithMasterPassword ,
99 clearUserEncryptionData ,
1010} from '../lib/encryption' ;
11+ import { logger } from '../lib/logger' ;
1112
1213// Global function to force all hook instances to refresh
1314export function forceGlobalMasterPasswordRefresh ( ) {
@@ -60,7 +61,11 @@ export function useMasterPassword() {
6061
6162 setLastCheckTime ( Date . now ( ) ) ;
6263 } catch ( error ) {
63- if ( __DEV__ ) console . error ( 'Error checking master password status:' , error ) ;
64+ logger . error ( 'Error checking master password status' , error as Error , {
65+ attributes : {
66+ userId,
67+ } ,
68+ } ) ;
6469 // On error, assume needs setup
6570 setIsNewSetup ( true ) ;
6671 setNeedsUnlock ( true ) ;
@@ -99,12 +104,23 @@ export function useMasterPassword() {
99104 if ( isNewSetup ) {
100105 // Setting up new master password
101106 await setupMasterPassword ( password , userId ) ;
107+ logger . recordEvent ( 'master_password_setup' , {
108+ userId,
109+ } ) ;
102110 } else {
103111 // Unlocking with existing password
104112 const success = await unlockWithMasterPassword ( password , userId ) ;
105113 if ( ! success ) {
114+ logger . warn ( 'Invalid master password attempt' , {
115+ attributes : {
116+ userId,
117+ } ,
118+ } ) ;
106119 throw new Error ( 'Invalid password' ) ;
107120 }
121+ logger . recordEvent ( 'master_password_unlocked' , {
122+ userId,
123+ } ) ;
108124 }
109125
110126 // Successfully authenticated - update state
@@ -122,7 +138,11 @@ export function useMasterPassword() {
122138 try {
123139 await clearUserEncryptionData ( userId ) ;
124140 } catch ( error ) {
125- if ( __DEV__ ) console . error ( 'Error clearing encryption data:' , error ) ;
141+ logger . error ( 'Error clearing encryption data on sign out' , error as Error , {
142+ attributes : {
143+ userId,
144+ } ,
145+ } ) ;
126146 }
127147 }
128148 } ;
0 commit comments