Skip to content

Commit 0896390

Browse files
committed
feat: Add comprehensive UI logging for sign-in and vault connection flows
- Log sign-in button clicks and flow progress - Log user/org state changes in WelcomeScreen - Log vault connection steps - All logs go to both console and export file
1 parent 0bb0c53 commit 0896390

File tree

2 files changed

+81
-11
lines changed

2 files changed

+81
-11
lines changed

src/components/MenuBar.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import { usePDMStore } from '../stores/pdmStore'
44
import { signInWithGoogle, signOut, isSupabaseConfigured, linkUserToOrganization } from '../lib/supabase'
55
import { SettingsModal } from './SettingsModal'
66

7+
// Helper to log to both console and electron log file
8+
const uiLog = (level: 'info' | 'warn' | 'error' | 'debug', message: string, data?: unknown) => {
9+
const logMsg = `[MenuBar] ${message}`
10+
if (level === 'error') console.error(logMsg, data || '')
11+
else if (level === 'warn') console.warn(logMsg, data || '')
12+
else console.log(logMsg, data || '')
13+
window.electronAPI?.log?.(level, `[MenuBar] ${message}`, data)
14+
}
15+
716
interface MenuBarProps {
817
onOpenVault?: () => void
918
onRefresh?: () => void
@@ -49,31 +58,47 @@ export function MenuBar({ minimal = false }: MenuBarProps) {
4958
}, [])
5059

5160
const handleSignIn = async () => {
52-
if (!isSupabaseConfigured) {
61+
uiLog('info', 'Sign in button clicked from MenuBar')
62+
63+
if (!isSupabaseConfigured()) {
64+
uiLog('warn', 'Supabase not configured')
5365
alert('Supabase is not configured. Please add VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY to your .env file.')
5466
return
5567
}
5668

5769
setIsSigningIn(true)
70+
uiLog('info', 'Starting Google sign-in flow from MenuBar')
71+
5872
try {
59-
const { error } = await signInWithGoogle()
73+
const { data, error } = await signInWithGoogle()
74+
uiLog('info', 'signInWithGoogle returned', {
75+
hasData: !!data,
76+
hasError: !!error,
77+
errorMessage: error?.message
78+
})
79+
6080
if (error) {
61-
console.error('Sign in error:', error)
81+
uiLog('error', 'Sign in failed', { error: error.message })
6282
alert(`Sign in failed: ${error.message}`)
83+
} else {
84+
uiLog('info', 'Sign in completed successfully, auth state change will be handled by App')
6385
}
64-
// The auth state change will be handled by the App component
6586
} catch (err) {
66-
console.error('Sign in error:', err)
87+
uiLog('error', 'Sign in exception', { error: String(err) })
6788
alert('Sign in failed. Check the console for details.')
6889
} finally {
90+
uiLog('info', 'Sign in flow finished, resetting state')
6991
setIsSigningIn(false)
7092
}
7193
}
7294

7395
const handleSignOut = async () => {
96+
uiLog('info', 'Sign out clicked')
7497
const { error } = await signOut()
7598
if (error) {
76-
console.error('Sign out error:', error)
99+
uiLog('error', 'Sign out error', { error: error.message })
100+
} else {
101+
uiLog('info', 'Sign out successful')
77102
}
78103
setUser(null)
79104
setOrganization(null)

src/components/WelcomeScreen.tsx

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import { FolderPlus, Loader2, HardDrive, WifiOff, LogIn, Check, Settings, Databa
33
import { usePDMStore, ConnectedVault } from '../stores/pdmStore'
44
import { 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
716
function 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

Comments
 (0)