@@ -3,6 +3,15 @@ import { FolderPlus, Loader2, HardDrive, WifiOff, LogIn, Check, Settings, Databa
33import { usePDMStore , ConnectedVault } from '../stores/pdmStore'
44import { signInWithGoogle , isSupabaseConfigured , supabase } from '../lib/supabase'
55
6+ // Helper to log to both console and electron log file
7+ const uiLog = ( level : 'info' | 'warn' | 'error' | 'debug' , message : string , data ?: unknown ) => {
8+ const logMsg = `[WelcomeScreen] ${ message } `
9+ if ( level === 'error' ) console . error ( logMsg , data || '' )
10+ else if ( level === 'warn' ) console . warn ( logMsg , data || '' )
11+ else console . log ( logMsg , data || '' )
12+ window . electronAPI ?. log ?.( level , `[WelcomeScreen] ${ message } ` , data )
13+ }
14+
615// Build vault path based on platform
716function buildVaultPath ( platform : string , vaultSlug : string ) : string {
817 if ( platform === 'darwin' ) {
@@ -74,9 +83,21 @@ export function WelcomeScreen({ onOpenVault, onOpenRecentVault }: WelcomeScreenP
7483 }
7584 } , [ ] )
7685
86+ // Log user/org state changes for debugging
87+ useEffect ( ( ) => {
88+ uiLog ( 'info' , 'User state changed' , {
89+ hasUser : ! ! user ,
90+ email : user ?. email ,
91+ hasOrg : ! ! organization ,
92+ orgName : organization ?. name ,
93+ isConnecting : isAuthConnecting
94+ } )
95+ } , [ user , organization , isAuthConnecting ] )
96+
7797 // Auto-connect on mount if we have connected vaults
7898 useEffect ( ( ) => {
7999 if ( connectedVaults . length > 0 && ( user || isOfflineMode ) ) {
100+ uiLog ( 'info' , 'Auto-connecting to vault' , { vaultName : connectedVaults [ 0 ] . name } )
80101 // Auto-connect to first connected vault
81102 const vault = connectedVaults [ 0 ]
82103 onOpenRecentVault ( vault . localPath )
@@ -132,22 +153,36 @@ export function WelcomeScreen({ onOpenVault, onOpenRecentVault }: WelcomeScreenP
132153 } , [ organization ?. id , vaultsRefreshKey ] ) // Refresh when vaultsRefreshKey changes
133154
134155 const handleSignIn = async ( ) => {
156+ uiLog ( 'info' , 'Sign in button clicked' )
157+
135158 if ( ! isSupabaseConfigured ( ) ) {
159+ uiLog ( 'warn' , 'Supabase not configured' )
136160 setStatusMessage ( 'Supabase not configured' )
137161 return
138162 }
139163
140164 setIsSigningIn ( true )
165+ uiLog ( 'info' , 'Starting Google sign-in flow' )
166+
141167 try {
142- const { error } = await signInWithGoogle ( )
168+ const { data, error } = await signInWithGoogle ( )
169+ uiLog ( 'info' , 'signInWithGoogle returned' , {
170+ hasData : ! ! data ,
171+ hasError : ! ! error ,
172+ errorMessage : error ?. message
173+ } )
174+
143175 if ( error ) {
144- console . error ( ' Sign in error: ', error )
176+ uiLog ( 'error' , ' Sign in failed ', { error : error . message } )
145177 setStatusMessage ( `Sign in failed: ${ error . message } ` )
178+ } else {
179+ uiLog ( 'info' , 'Sign in completed successfully' )
146180 }
147181 } catch ( err ) {
148- console . error ( ' Sign in error: ', err )
182+ uiLog ( 'error' , ' Sign in exception ', { error : String ( err ) } )
149183 setStatusMessage ( 'Sign in failed' )
150184 } finally {
185+ uiLog ( 'info' , 'Sign in flow finished, resetting state' )
151186 setIsSigningIn ( false )
152187 }
153188 }
@@ -157,14 +192,22 @@ export function WelcomeScreen({ onOpenVault, onOpenRecentVault }: WelcomeScreenP
157192 }
158193
159194 const handleConnectVault = async ( vault : Vault ) => {
160- if ( ! window . electronAPI ) return
195+ uiLog ( 'info' , 'Connect vault clicked' , { vaultName : vault . name , vaultId : vault . id } )
196+
197+ if ( ! window . electronAPI ) {
198+ uiLog ( 'error' , 'electronAPI not available' )
199+ return
200+ }
161201
162202 setConnectingVaultId ( vault . id )
163203
164204 try {
165205 // Create vault folder based on platform
166206 const vaultPath = buildVaultPath ( platform , vault . slug )
207+ uiLog ( 'info' , 'Creating working directory' , { vaultPath, platform } )
208+
167209 const result = await window . electronAPI . createWorkingDir ( vaultPath )
210+ uiLog ( 'info' , 'createWorkingDir result' , { success : result . success , path : result . path , error : result . error } )
168211
169212 if ( result . success && result . path ) {
170213 // Add to connected vaults
@@ -175,15 +218,17 @@ export function WelcomeScreen({ onOpenVault, onOpenRecentVault }: WelcomeScreenP
175218 isExpanded : true
176219 }
177220 addConnectedVault ( connectedVault )
221+ uiLog ( 'info' , 'Vault connected, opening' , { vaultName : vault . name } )
178222
179223 // Open the vault
180224 onOpenRecentVault ( result . path )
181225 addToast ( 'success' , `Connected to "${ vault . name } "` )
182226 } else {
227+ uiLog ( 'error' , 'Failed to create vault folder' , { error : result . error } )
183228 addToast ( 'error' , result . error || 'Failed to create vault folder' )
184229 }
185230 } catch ( err ) {
186- console . error ( 'Error connecting to vault: ', err )
231+ uiLog ( 'error' , 'Exception connecting to vault', { error : String ( err ) } )
187232 addToast ( 'error' , 'Failed to connect to vault' )
188233 } finally {
189234 setConnectingVaultId ( null )
0 commit comments