From d0415756006cf6ed3621c75a1773cfbec7f07370 Mon Sep 17 00:00:00 2001 From: echo Date: Sun, 22 Feb 2026 04:49:38 +0100 Subject: [PATCH] logs removed --- backend/src/modules/push/push.controller.ts | 6 --- backend/src/modules/push/push.service.ts | 9 +---- pwa/eslint.config.js | 2 +- pwa/src/components/ui/notification-banner.tsx | 15 ++----- pwa/src/hooks/usePushNotifications.ts | 38 ++---------------- pwa/src/lib/push-api.ts | 39 +++++-------------- pwa/src/main.tsx | 10 ----- 7 files changed, 18 insertions(+), 101 deletions(-) diff --git a/backend/src/modules/push/push.controller.ts b/backend/src/modules/push/push.controller.ts index 042234a..80606f5 100644 --- a/backend/src/modules/push/push.controller.ts +++ b/backend/src/modules/push/push.controller.ts @@ -30,12 +30,6 @@ export class PushController { @Post('subscribe') @HttpCode(HttpStatus.CREATED) async subscribe(@Body() dto: SubscribeDto): Promise<{ success: boolean }> { - console.log('Received push subscription:', { - endpoint: dto.endpoint?.substring(0, 50) + '...', - hasP256dh: !!dto.p256dh, - hasAuth: !!dto.auth, - userId: dto.userId, - }); await this.pushService.subscribe(dto); return { success: true }; } diff --git a/backend/src/modules/push/push.service.ts b/backend/src/modules/push/push.service.ts index e4a8593..b780a17 100644 --- a/backend/src/modules/push/push.service.ts +++ b/backend/src/modules/push/push.service.ts @@ -49,15 +49,11 @@ export class PushService implements OnModuleInit { } async subscribe(dto: SubscribeDto): Promise { - this.logger.log('Subscribing push notification...'); - this.logger.debug(`Endpoint: ${dto.endpoint?.substring(0, 50)}...`); - const existing = await this.subscriptionRepo.findOne({ where: { endpoint: dto.endpoint }, }); if (existing) { - this.logger.log('Subscription already exists, updating...'); if (dto.userId && existing.userId !== dto.userId) { existing.userId = dto.userId; return this.subscriptionRepo.save(existing); @@ -65,7 +61,6 @@ export class PushService implements OnModuleInit { return existing; } - this.logger.log('Creating new subscription...'); const subscription = this.subscriptionRepo.create({ endpoint: dto.endpoint, p256dh: dto.p256dh, @@ -73,9 +68,7 @@ export class PushService implements OnModuleInit { userId: dto.userId ?? null, }); - const saved = await this.subscriptionRepo.save(subscription); - this.logger.log(`Subscription saved with ID: ${saved.id}`); - return saved; + return this.subscriptionRepo.save(subscription); } async unsubscribe(dto: UnsubscribeDto): Promise { diff --git a/pwa/eslint.config.js b/pwa/eslint.config.js index 5e6b472..9727b56 100644 --- a/pwa/eslint.config.js +++ b/pwa/eslint.config.js @@ -6,7 +6,7 @@ import tseslint from 'typescript-eslint' import { defineConfig, globalIgnores } from 'eslint/config' export default defineConfig([ - globalIgnores(['dist']), + globalIgnores(['dist', 'dev-dist']), { files: ['**/*.{ts,tsx}'], extends: [ diff --git a/pwa/src/components/ui/notification-banner.tsx b/pwa/src/components/ui/notification-banner.tsx index c586dae..0ea7310 100644 --- a/pwa/src/components/ui/notification-banner.tsx +++ b/pwa/src/components/ui/notification-banner.tsx @@ -32,18 +32,9 @@ export function NotificationBanner() { }; const handleSubscribe = async () => { - console.log('handleSubscribe called'); - console.log('isSupported:', isSupported); - console.log('isSubscribed:', isSubscribed); - - try { - const success = await subscribe(); - console.log('subscribe() returned:', success); - if (success) { - setIsVisible(false); - } - } catch (error) { - console.error('handleSubscribe error:', error); + const success = await subscribe(); + if (success) { + setIsVisible(false); } }; diff --git a/pwa/src/hooks/usePushNotifications.ts b/pwa/src/hooks/usePushNotifications.ts index a822a54..0a6c4b7 100644 --- a/pwa/src/hooks/usePushNotifications.ts +++ b/pwa/src/hooks/usePushNotifications.ts @@ -40,25 +40,16 @@ export function usePushNotifications(): UsePushNotificationsReturn { const [permissionState, setPermissionState] = useState(getInitialPermission); const hasCheckedRef = useRef(false); - useEffect(() => { - console.log('usePushNotifications - isSupported:', checkPushSupport()); - console.log('usePushNotifications - permissionState:', getInitialPermission()); - }, []); - useEffect(() => { if (!isSupported || hasCheckedRef.current) return; hasCheckedRef.current = true; - console.log('Checking existing push subscription...'); navigator.serviceWorker.ready .then((registration) => registration.pushManager.getSubscription()) .then((subscription) => { - console.log('Existing subscription:', subscription); setIsSubscribed(!!subscription); }) - .catch((error) => { - console.error('Error checking subscription:', error); - }); + .catch(() => {}); }, [isSupported]); const requestPermission = @@ -78,38 +69,26 @@ export function usePushNotifications(): UsePushNotificationsReturn { try { const permission = await requestPermission(); if (permission !== 'granted') { - console.log('Push permission denied'); setIsLoading(false); return false; } const publicKey = await getVapidPublicKey(); if (!publicKey) { - console.error('VAPID public key not available'); setIsLoading(false); return false; } - console.log('Got VAPID public key, subscribing...'); - - // Check if service worker is already ready - console.log('Checking service worker status...'); - const swController = navigator.serviceWorker.controller; - console.log('Service worker controller:', swController); - - // Wait for service worker to be ready with timeout const registration = await Promise.race([ navigator.serviceWorker.ready, new Promise((_, reject) => { setTimeout(() => { - reject(new Error('Service worker ready timeout after 10s')); + reject(new Error('Service worker ready timeout')); }, 10000); }), ]); - console.log('Service worker ready:', registration); if (!registration.pushManager) { - console.error('PushManager not available in service worker registration'); setIsLoading(false); return false; } @@ -117,31 +96,24 @@ export function usePushNotifications(): UsePushNotificationsReturn { let subscription = await registration.pushManager.getSubscription(); if (!subscription) { - console.log('Creating new push subscription...'); subscription = await registration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: urlBase64ToUint8Array(publicKey), }); - console.log('Push subscription created'); - } else { - console.log('Existing push subscription found'); } const subJson = subscription.toJSON(); - console.log('Subscription JSON:', subJson); if ( !subJson.endpoint || !subJson.keys?.p256dh || !subJson.keys?.auth ) { - console.error('Invalid subscription data:', subJson); setIsLoading(false); return false; } const success = await subscribeToPush(subJson as PushSubscriptionData); - console.log('Subscribe to push result:', success); if (success) { setIsSubscribed(true); @@ -150,8 +122,7 @@ export function usePushNotifications(): UsePushNotificationsReturn { setIsLoading(false); return success; - } catch (error) { - console.error('Error subscribing to push notifications:', error); + } catch { setIsLoading(false); return false; } @@ -175,8 +146,7 @@ export function usePushNotifications(): UsePushNotificationsReturn { localStorage.removeItem(STORAGE_KEY); setIsLoading(false); return true; - } catch (error) { - console.error('Error unsubscribing from push notifications:', error); + } catch { setIsLoading(false); return false; } diff --git a/pwa/src/lib/push-api.ts b/pwa/src/lib/push-api.ts index 97586f2..8a9ef0f 100644 --- a/pwa/src/lib/push-api.ts +++ b/pwa/src/lib/push-api.ts @@ -20,8 +20,7 @@ export async function getVapidPublicKey(): Promise { } const data: VapidPublicKeyResponse = await response.json(); return data.publicKey; - } catch (error) { - console.error('Error fetching VAPID public key:', error); + } catch { return null; } } @@ -30,39 +29,20 @@ export async function subscribeToPush( subscription: PushSubscriptionData, ): Promise { try { - console.log('Sending subscription to server:', { - endpoint: subscription.endpoint, - hasKeys: !!subscription.keys, - }); - - const payload = { - endpoint: subscription.endpoint, - p256dh: subscription.keys.p256dh, - auth: subscription.keys.auth, - }; - - console.log('Payload:', payload); - console.log('API URL:', `${API_BASE_URL}/push/subscribe`); - const response = await fetch(`${API_BASE_URL}/push/subscribe`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(payload), + body: JSON.stringify({ + endpoint: subscription.endpoint, + p256dh: subscription.keys.p256dh, + auth: subscription.keys.auth, + }), }); - console.log('Subscribe response status:', response.status); - - if (!response.ok) { - const errorText = await response.text(); - console.error('Subscribe failed:', errorText); - return false; - } - - return true; - } catch (error) { - console.error('Error subscribing to push:', error); + return response.ok; + } catch { return false; } } @@ -79,8 +59,7 @@ export async function unsubscribeFromPush( body: JSON.stringify({ endpoint }), }); return response.ok; - } catch (error) { - console.error('Error unsubscribing from push:', error); + } catch { return false; } } diff --git a/pwa/src/main.tsx b/pwa/src/main.tsx index e655a2f..8737dba 100644 --- a/pwa/src/main.tsx +++ b/pwa/src/main.tsx @@ -11,22 +11,12 @@ initializeTheme() const queryClient = new QueryClient() -// Register service worker const updateSW = registerSW({ onNeedRefresh() { if (confirm('New content available. Reload?')) { updateSW(true) } }, - onOfflineReady() { - console.log('App ready to work offline') - }, - onRegistered(registration) { - console.log('SW Registered:', registration?.scope) - }, - onRegisterError(error) { - console.error('SW registration error:', error) - }, }) ReactDOM.createRoot(document.getElementById('root')!).render(