Skip to content

Commit 94ce384

Browse files
committed
Removes debug logs, refines error handling
Eliminates excessive console output for a cleaner codebase and transitions to minimal error messages. Removes legacy debugging utilities to improve production readiness and reduce noise.
1 parent a936a40 commit 94ce384

File tree

12 files changed

+35
-247
lines changed

12 files changed

+35
-247
lines changed

editor/src/components/FacilityDropdown.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState, useRef, useEffect } from 'react';
22
import { useQuery } from 'urql';
33
import { GET_FACILITIES_WITH_ACCESS, TEST_QUERY } from '../graphql/queries';
44
import { debugEnvironment } from '../lib/debug-env';
5-
import { logEnvironmentInfo, logAuthError } from '../utils/debugUtils';
5+
66

77
interface Facility {
88
id: string;
@@ -42,13 +42,11 @@ export const FacilityDropdown: React.FC<FacilityDropdownProps> = ({
4242
}, []);
4343

4444
// Log detailed debugging info
45-
console.log('🧪 Test Query Result:', testResult);
46-
console.log('🏢 Facilities Query Result:', { data, fetching, error });
45+
4746

4847
// Enhanced error logging
4948
if (error && import.meta.env.DEV) {
50-
logEnvironmentInfo();
51-
logAuthError(error, 'Facilities Query');
49+
console.error('Facilities Query Error:', error);
5250
}
5351

5452
// Close dropdown when clicking outside

editor/src/components/FacilitySelectorPortal.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const FacilitySelectorPortal: React.FC<FacilitySelectorPortalProps> = ({
6060
const facilityToRestore = facilities.find((facility: Facility) => facility.id === selectedFacilityId);
6161
if (facilityToRestore) {
6262
onFacilitySelect(facilityToRestore);
63-
console.log('Restored facility object from facilities list:', facilityToRestore);
63+
6464
}
6565
}
6666
}, [facilities, selectedFacilityId, selectedFacility, onFacilitySelect]);
@@ -95,25 +95,6 @@ export const FacilitySelectorPortal: React.FC<FacilitySelectorPortalProps> = ({
9595
// Get facilities for current tab
9696
const currentFacilities = groupedFacilities[activeTab];
9797

98-
// Log access information for debugging
99-
if (data?.facilities?.items && facilities.length > 0) {
100-
console.log('🔍 Facility Access Debug:');
101-
facilities.slice(0, 3).forEach((facility: Facility) => {
102-
console.log(` ${facility.name}:`, {
103-
kind: facility.kind,
104-
developerAccess: facility.developerAccess,
105-
apiDeveloperAccess: facility.apiDeveloperAccess,
106-
hasAccess: hasDeveloperAccess(facility)
107-
});
108-
});
109-
console.log(`📊 Grouped facilities:`, {
110-
Total: facilitiesWithAccess.length,
111-
All: groupedFacilities.All.length,
112-
Indoor: groupedFacilities.Indoor.length,
113-
Range: groupedFacilities.Range.length
114-
});
115-
}
116-
11798
const handleFacilityClick = (facility: Facility) => {
11899
if (selectedFacility?.id === facility.id) {
119100
// Deselect if clicking the same facility

editor/src/components/StepDialog.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const StepDialog: React.FC<StepDialogProps> = ({ open, onClose, onAdd, pa
1818

1919
// Whenever dialog is (re)opened or parent activity type changes, reset the fields.
2020
useEffect(() => {
21-
console.log('🔍 StepDialog useEffect:', { open, parentActivityType, parentActivityId });
21+
2222
if (open) {
2323
setId('');
2424
setHeader('');
@@ -77,9 +77,7 @@ export const StepDialog: React.FC<StepDialogProps> = ({ open, onClose, onAdd, pa
7777
<button
7878
disabled={!id || !header}
7979
onClick={() => {
80-
console.log('🔍 StepDialog Add Step button clicked:', { parentActivityType, parentActivityId, id, header });
8180
if (!parentActivityType || !parentActivityId) {
82-
console.log('🔍 Missing parent info, returning early');
8381
return;
8482
}
8583
const step: Step = createStep({
@@ -88,7 +86,7 @@ export const StepDialog: React.FC<StepDialogProps> = ({ open, onClose, onAdd, pa
8886
introHeader: header,
8987
introDescription: description,
9088
});
91-
console.log('🔍 Created step:', step);
89+
9290
onAdd(step, parentActivityId);
9391
onClose();
9492
}}

editor/src/components/TopBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const TopBar: React.FC<TopBarProps> = ({
2626

2727
const handleFacilitySelect = (facility: Facility | null) => {
2828
onFacilitySelect(facility);
29-
console.log('Selected facility:', facility);
29+
3030
// - Storing selection in localStorage
3131
};
3232

editor/src/editorReducer.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
5252
selectedRef: action.select ? { kind: 'activity', activityId: action.activity.id } : state.selectedRef
5353
};
5454
case 'ADD_STEP': {
55-
console.log('🔍 ADD_STEP reducer:', {
56-
parentActivityId: action.parentActivityId,
57-
stepId: action.step.id,
58-
select: action.select,
59-
currentActivities: state.script.activities.map(a => ({ id: a.id, stepCount: a.steps.length }))
60-
});
55+
6156

6257
const activities = state.script.activities.map(a =>
6358
a.id === action.parentActivityId ? { ...a, steps: [...a.steps, action.step] } : a
@@ -69,10 +64,7 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
6964
selectedRef: action.select ? { kind: 'step' as const, activityId: action.parentActivityId, stepId: action.step.id } : state.selectedRef
7065
};
7166

72-
console.log('🔍 ADD_STEP result:', {
73-
newActivities: newState.script.activities.map(a => ({ id: a.id, stepCount: a.steps.length, steps: a.steps.map(s => s.id) })),
74-
newSelectedRef: newState.selectedRef
75-
});
67+
7668

7769
return newState;
7870
}

editor/src/lib/AuthProvider.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,19 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
3131
const checkAuthStatus = () => {
3232
// Only check for OAuth tokens (user authentication), not client credential tokens
3333
const isAuth = authService.isAuthenticated();
34-
console.log('🔍 Checking auth status:', { isAuth, hasStoredToken: !!localStorage.getItem('trackman_auth_token') });
3534

3635
setIsAuthenticated(isAuth);
3736
setIsLoading(false);
3837

3938
if (!isAuth) {
40-
console.log('❌ Not authenticated - user needs to log in');
4139
setError(null); // Don't show error for unauthenticated state
4240
} else {
43-
console.log('✅ User is authenticated');
4441
setError(null);
4542
}
4643
};
4744

4845
const login = async () => {
4946
// Client credential authentication has been removed - only OAuth login is supported
50-
console.log('❌ Client credential login is no longer supported. Use OAuth login instead.');
5147
throw new Error('Client credential authentication is disabled. Please use OAuth login.');
5248
};
5349

@@ -71,13 +67,11 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
7167
setIsLoading(true);
7268
try {
7369
await authService.logoutOAuth();
74-
console.log('🔓 Logged out successfully, auth service will handle redirect...');
7570
// Don't reload here - let the auth service handle the redirect to logout completion page
7671
} catch (err) {
7772
// Fallback to local logout if server logout fails
7873
console.warn('⚠️ Server logout failed, falling back to local logout:', err);
7974
authService.clearToken();
80-
console.log('🔓 Logged out locally, redirecting to login...');
8175
// Only reload if the auth service logout failed
8276
window.location.reload();
8377
}
@@ -91,7 +85,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
9185
authService.clearToken();
9286
await authService.getAccessToken();
9387
setIsAuthenticated(true);
94-
console.log('🔄 Token refreshed successfully');
88+
9589
} catch (err) {
9690
const errorMessage = err instanceof Error ? err.message : 'Token refresh failed';
9791
setError(errorMessage);

editor/src/lib/auth-service.ts

Lines changed: 21 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface TokenResponse {
77
}
88

99
interface TokenData {
10-
accessToken: string;
10+
cessToken: string;
1111
tokenType: string;
1212
expiresAt: Date;
1313
refreshToken?: string;
@@ -35,15 +35,11 @@ class AuthService {
3535
* Get a valid access token (user tokens only - no client credentials)
3636
*/
3737
public async getAccessToken(): Promise<string> {
38-
console.log('🎫 getAccessToken() called');
39-
4038
// Only return user tokens, never client credential tokens
4139
if (this.tokenData && this.isTokenValid() && this.isAuthenticated()) {
42-
console.log('✅ Using existing valid user token');
4340
return this.tokenData.accessToken;
4441
}
4542

46-
console.log('❌ No valid user token available - client must authenticate via OAuth');
4743
throw new Error('No valid user token available. User must log in via OAuth.');
4844
}
4945

@@ -83,10 +79,6 @@ class AuthService {
8379
*/
8480
private loadTokenFromStorage(): void {
8581
const stored = localStorage.getItem('trackman_auth_token');
86-
console.log('🔍 Loading token from storage:', {
87-
hasStoredToken: !!stored,
88-
tokenPreview: stored ? stored.substring(0, 50) + '...' : 'none'
89-
});
9082

9183
if (stored) {
9284
try {
@@ -98,17 +90,8 @@ class AuthService {
9890
scope: parsed.scope,
9991
};
10092

101-
console.log('📦 Loaded token data:', {
102-
hasAccessToken: !!this.tokenData.accessToken,
103-
tokenType: this.tokenData.tokenType,
104-
expiresAt: this.tokenData.expiresAt,
105-
scope: this.tokenData.scope,
106-
isValid: this.isTokenValid()
107-
});
108-
10993
// Clean up if token is expired
11094
if (!this.isTokenValid()) {
111-
console.log('🗑️ Token is expired, clearing...');
11295
this.clearToken();
11396
}
11497
} catch (error) {
@@ -122,8 +105,6 @@ class AuthService {
122105
* Clear the current token and all authentication state
123106
*/
124107
public clearToken(): void {
125-
console.log('🧹 Clearing all authentication tokens and state...');
126-
127108
// Clear in-memory token
128109
this.tokenData = null;
129110

@@ -136,17 +117,13 @@ class AuthService {
136117
sessionStorage.removeItem('oauth_code_verifier');
137118
sessionStorage.removeItem('oauth_state');
138119
sessionStorage.removeItem('oauth_processed');
139-
140-
console.log('✅ All authentication state cleared');
141120
}
142121

143122
/**
144123
* Force clear all authentication state and reload the page
145124
* Use this to completely reset authentication for testing
146125
*/
147126
public forceResetAuthentication(): void {
148-
console.log('🔴 Force resetting all authentication...');
149-
150127
// Clear all storage
151128
localStorage.clear();
152129
sessionStorage.clear();
@@ -155,7 +132,6 @@ class AuthService {
155132
this.tokenData = null;
156133
this.tokenRefreshPromise = null;
157134

158-
console.log('🔄 Reloading page to complete reset...');
159135
window.location.href = window.location.origin;
160136
}
161137

@@ -172,40 +148,41 @@ class AuthService {
172148
try {
173149
localStorage.clear();
174150
sessionStorage.clear();
175-
console.log('🧹 Cleared all browser storage');
151+
176152
} catch (error) {
177153
console.warn('Failed to clear storage:', error);
178154
}
179155

180-
// Use TrackMan portal approach: redirect directly to server logout endpoint
181-
// This lets the OAuth server handle session clearing and proper logout flow
156+
// Mimic what the portal's /account/logout endpoint does:
157+
// Redirect to OAuth logout with returnUrl parameter (exactly like portal)
182158
try {
183159
const { ENV_URLS, OAUTH_CONFIG } = await import('./env');
184160

185-
// Build logout URL with returnUrl parameter (exactly like portal approach)
161+
// This is what we want to return to after logout
186162
const returnUrl = `${window.location.origin}/?logout_complete=true&t=${Date.now()}`;
163+
164+
// Build the OAuth logout URL exactly like the portal's server would
187165
const logoutUrl = new URL(`${ENV_URLS.loginBase}/connect/endsession`);
188166

189-
// Add required parameters for proper logout
190167
if (OAUTH_CONFIG.webClientId) {
191168
logoutUrl.searchParams.set('client_id', OAUTH_CONFIG.webClientId);
192169
}
193170

194-
// Use both standard OAuth parameter and portal-style returnUrl
195-
logoutUrl.searchParams.set('post_logout_redirect_uri', returnUrl);
196-
logoutUrl.searchParams.set('returnUrl', encodeURIComponent(returnUrl)); // Portal style
171+
// Use the same returnUrl parameter format as the portal
172+
logoutUrl.searchParams.set('returnUrl', returnUrl);
197173

198-
console.log('🔄 Redirecting to TrackMan logout endpoint:', logoutUrl.toString());
174+
console.log('🔄 Mimicking portal logout: redirecting to OAuth logout with returnUrl');
175+
console.log('� OAuth logout URL:', logoutUrl.toString());
199176
console.log('🔍 Return URL after logout:', returnUrl);
200177

201-
// Direct redirect to OAuth server logout (like portal does)
178+
// Redirect to OAuth logout (this is what portal's /account/logout does)
202179
window.location.href = logoutUrl.toString();
203180

204181
} catch (error) {
205-
console.error('❌ Failed to build logout URL:', error);
206-
// Fallback to simple logout completion page
182+
console.error('❌ Failed to build OAuth logout URL:', error);
183+
// Fallback
207184
const fallbackUrl = `${window.location.origin}/?logout_complete=true&t=${Date.now()}`;
208-
console.log('🔄 Fallback: Redirecting to logout completion page:', fallbackUrl);
185+
209186
window.location.href = fallbackUrl;
210187
}
211188
}
@@ -223,12 +200,7 @@ class AuthService {
223200
const scope = this.tokenData.scope || '';
224201
const hasUserScopes = scope.includes('openid') || scope.includes('profile') || scope.includes('email');
225202

226-
console.log('🔍 Authentication check:', {
227-
hasToken: !!this.tokenData,
228-
isValid: this.isTokenValid(),
229-
scope: scope,
230-
hasUserScopes: hasUserScopes
231-
});
203+
232204

233205
return hasUserScopes;
234206
}
@@ -247,19 +219,7 @@ class AuthService {
247219
const { buildAuthorizationUrl, generateCodeVerifier, generateState } = await import('./oauth2-utils');
248220
const { ENV_URLS, OAUTH_CONFIG } = await import('./env');
249221

250-
console.log('🚀 Starting OAuth login flow...');
251-
console.log('🔍 startOAuthLogin called with prompt parameter:', prompt);
252-
if (prompt) {
253-
console.log('🔑 Using prompt parameter:', prompt, '- This will force login screen');
254-
} else {
255-
console.log('⚠️ No prompt parameter provided - may auto-login if server session exists');
256-
}
257-
console.log('OAuth Config:', {
258-
webClientId: OAUTH_CONFIG.webClientId,
259-
redirectUri: OAUTH_CONFIG.redirectUri,
260-
loginBaseUrl: ENV_URLS.loginBase,
261-
scopes: OAUTH_CONFIG.scopes
262-
});
222+
263223

264224
// Check for required configuration
265225
if (!OAUTH_CONFIG.webClientId) {
@@ -279,10 +239,7 @@ class AuthService {
279239
const codeVerifier = generateCodeVerifier();
280240
const state = generateState();
281241

282-
console.log('📝 Generated PKCE parameters:', {
283-
codeVerifierLength: codeVerifier.length,
284-
stateLength: state.length
285-
});
242+
286243

287244
// Store PKCE parameters in sessionStorage for callback
288245
sessionStorage.setItem('oauth_code_verifier', codeVerifier);
@@ -301,8 +258,7 @@ class AuthService {
301258
prompt
302259
);
303260

304-
console.log('🔗 Authorization URL:', authUrl);
305-
console.log('🌐 About to redirect to TrackMan login server...');
261+
306262

307263
// Redirect to login server
308264
window.location.href = authUrl;
@@ -315,7 +271,7 @@ class AuthService {
315271
const { parseAuthorizationCallback, exchangeCodeForToken } = await import('./oauth2-utils');
316272
const { ENV_URLS, OAUTH_CONFIG } = await import('./env');
317273

318-
console.log('🔄 Processing OAuth callback...');
274+
319275

320276
// Parse callback URL
321277
const { code, state, error, error_description } = parseAuthorizationCallback(callbackUrl);
@@ -367,9 +323,7 @@ class AuthService {
367323
this.tokenData = tokenData;
368324
this.saveTokenToStorage();
369325

370-
console.log('✅ OAuth login successful!');
371-
console.log(' Token expires at:', tokenData.expiresAt);
372-
console.log(' Scopes:', tokenData.scope);
326+
373327

374328
} finally {
375329
// Clean up session storage

0 commit comments

Comments
 (0)