logs removed

This commit is contained in:
echo 2026-02-22 04:49:38 +01:00
parent 57864e00da
commit d041575600
7 changed files with 18 additions and 101 deletions

View File

@ -30,12 +30,6 @@ export class PushController {
@Post('subscribe') @Post('subscribe')
@HttpCode(HttpStatus.CREATED) @HttpCode(HttpStatus.CREATED)
async subscribe(@Body() dto: SubscribeDto): Promise<{ success: boolean }> { 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); await this.pushService.subscribe(dto);
return { success: true }; return { success: true };
} }

View File

@ -49,15 +49,11 @@ export class PushService implements OnModuleInit {
} }
async subscribe(dto: SubscribeDto): Promise<PushSubscriptionEntity> { async subscribe(dto: SubscribeDto): Promise<PushSubscriptionEntity> {
this.logger.log('Subscribing push notification...');
this.logger.debug(`Endpoint: ${dto.endpoint?.substring(0, 50)}...`);
const existing = await this.subscriptionRepo.findOne({ const existing = await this.subscriptionRepo.findOne({
where: { endpoint: dto.endpoint }, where: { endpoint: dto.endpoint },
}); });
if (existing) { if (existing) {
this.logger.log('Subscription already exists, updating...');
if (dto.userId && existing.userId !== dto.userId) { if (dto.userId && existing.userId !== dto.userId) {
existing.userId = dto.userId; existing.userId = dto.userId;
return this.subscriptionRepo.save(existing); return this.subscriptionRepo.save(existing);
@ -65,7 +61,6 @@ export class PushService implements OnModuleInit {
return existing; return existing;
} }
this.logger.log('Creating new subscription...');
const subscription = this.subscriptionRepo.create({ const subscription = this.subscriptionRepo.create({
endpoint: dto.endpoint, endpoint: dto.endpoint,
p256dh: dto.p256dh, p256dh: dto.p256dh,
@ -73,9 +68,7 @@ export class PushService implements OnModuleInit {
userId: dto.userId ?? null, userId: dto.userId ?? null,
}); });
const saved = await this.subscriptionRepo.save(subscription); return this.subscriptionRepo.save(subscription);
this.logger.log(`Subscription saved with ID: ${saved.id}`);
return saved;
} }
async unsubscribe(dto: UnsubscribeDto): Promise<void> { async unsubscribe(dto: UnsubscribeDto): Promise<void> {

View File

@ -6,7 +6,7 @@ import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config' import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([ export default defineConfig([
globalIgnores(['dist']), globalIgnores(['dist', 'dev-dist']),
{ {
files: ['**/*.{ts,tsx}'], files: ['**/*.{ts,tsx}'],
extends: [ extends: [

View File

@ -32,19 +32,10 @@ export function NotificationBanner() {
}; };
const handleSubscribe = async () => { const handleSubscribe = async () => {
console.log('handleSubscribe called');
console.log('isSupported:', isSupported);
console.log('isSubscribed:', isSubscribed);
try {
const success = await subscribe(); const success = await subscribe();
console.log('subscribe() returned:', success);
if (success) { if (success) {
setIsVisible(false); setIsVisible(false);
} }
} catch (error) {
console.error('handleSubscribe error:', error);
}
}; };
if (!isVisible || isSubscribed || isDismissed) { if (!isVisible || isSubscribed || isDismissed) {

View File

@ -40,25 +40,16 @@ export function usePushNotifications(): UsePushNotificationsReturn {
const [permissionState, setPermissionState] = useState(getInitialPermission); const [permissionState, setPermissionState] = useState(getInitialPermission);
const hasCheckedRef = useRef(false); const hasCheckedRef = useRef(false);
useEffect(() => {
console.log('usePushNotifications - isSupported:', checkPushSupport());
console.log('usePushNotifications - permissionState:', getInitialPermission());
}, []);
useEffect(() => { useEffect(() => {
if (!isSupported || hasCheckedRef.current) return; if (!isSupported || hasCheckedRef.current) return;
hasCheckedRef.current = true; hasCheckedRef.current = true;
console.log('Checking existing push subscription...');
navigator.serviceWorker.ready navigator.serviceWorker.ready
.then((registration) => registration.pushManager.getSubscription()) .then((registration) => registration.pushManager.getSubscription())
.then((subscription) => { .then((subscription) => {
console.log('Existing subscription:', subscription);
setIsSubscribed(!!subscription); setIsSubscribed(!!subscription);
}) })
.catch((error) => { .catch(() => {});
console.error('Error checking subscription:', error);
});
}, [isSupported]); }, [isSupported]);
const requestPermission = const requestPermission =
@ -78,38 +69,26 @@ export function usePushNotifications(): UsePushNotificationsReturn {
try { try {
const permission = await requestPermission(); const permission = await requestPermission();
if (permission !== 'granted') { if (permission !== 'granted') {
console.log('Push permission denied');
setIsLoading(false); setIsLoading(false);
return false; return false;
} }
const publicKey = await getVapidPublicKey(); const publicKey = await getVapidPublicKey();
if (!publicKey) { if (!publicKey) {
console.error('VAPID public key not available');
setIsLoading(false); setIsLoading(false);
return 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([ const registration = await Promise.race([
navigator.serviceWorker.ready, navigator.serviceWorker.ready,
new Promise<ServiceWorkerRegistration>((_, reject) => { new Promise<ServiceWorkerRegistration>((_, reject) => {
setTimeout(() => { setTimeout(() => {
reject(new Error('Service worker ready timeout after 10s')); reject(new Error('Service worker ready timeout'));
}, 10000); }, 10000);
}), }),
]); ]);
console.log('Service worker ready:', registration);
if (!registration.pushManager) { if (!registration.pushManager) {
console.error('PushManager not available in service worker registration');
setIsLoading(false); setIsLoading(false);
return false; return false;
} }
@ -117,31 +96,24 @@ export function usePushNotifications(): UsePushNotificationsReturn {
let subscription = await registration.pushManager.getSubscription(); let subscription = await registration.pushManager.getSubscription();
if (!subscription) { if (!subscription) {
console.log('Creating new push subscription...');
subscription = await registration.pushManager.subscribe({ subscription = await registration.pushManager.subscribe({
userVisibleOnly: true, userVisibleOnly: true,
applicationServerKey: urlBase64ToUint8Array(publicKey), applicationServerKey: urlBase64ToUint8Array(publicKey),
}); });
console.log('Push subscription created');
} else {
console.log('Existing push subscription found');
} }
const subJson = subscription.toJSON(); const subJson = subscription.toJSON();
console.log('Subscription JSON:', subJson);
if ( if (
!subJson.endpoint || !subJson.endpoint ||
!subJson.keys?.p256dh || !subJson.keys?.p256dh ||
!subJson.keys?.auth !subJson.keys?.auth
) { ) {
console.error('Invalid subscription data:', subJson);
setIsLoading(false); setIsLoading(false);
return false; return false;
} }
const success = await subscribeToPush(subJson as PushSubscriptionData); const success = await subscribeToPush(subJson as PushSubscriptionData);
console.log('Subscribe to push result:', success);
if (success) { if (success) {
setIsSubscribed(true); setIsSubscribed(true);
@ -150,8 +122,7 @@ export function usePushNotifications(): UsePushNotificationsReturn {
setIsLoading(false); setIsLoading(false);
return success; return success;
} catch (error) { } catch {
console.error('Error subscribing to push notifications:', error);
setIsLoading(false); setIsLoading(false);
return false; return false;
} }
@ -175,8 +146,7 @@ export function usePushNotifications(): UsePushNotificationsReturn {
localStorage.removeItem(STORAGE_KEY); localStorage.removeItem(STORAGE_KEY);
setIsLoading(false); setIsLoading(false);
return true; return true;
} catch (error) { } catch {
console.error('Error unsubscribing from push notifications:', error);
setIsLoading(false); setIsLoading(false);
return false; return false;
} }

View File

@ -20,8 +20,7 @@ export async function getVapidPublicKey(): Promise<string | null> {
} }
const data: VapidPublicKeyResponse = await response.json(); const data: VapidPublicKeyResponse = await response.json();
return data.publicKey; return data.publicKey;
} catch (error) { } catch {
console.error('Error fetching VAPID public key:', error);
return null; return null;
} }
} }
@ -30,39 +29,20 @@ export async function subscribeToPush(
subscription: PushSubscriptionData, subscription: PushSubscriptionData,
): Promise<boolean> { ): Promise<boolean> {
try { 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`, { const response = await fetch(`${API_BASE_URL}/push/subscribe`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', '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); return response.ok;
} catch {
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 false; return false;
} }
} }
@ -79,8 +59,7 @@ export async function unsubscribeFromPush(
body: JSON.stringify({ endpoint }), body: JSON.stringify({ endpoint }),
}); });
return response.ok; return response.ok;
} catch (error) { } catch {
console.error('Error unsubscribing from push:', error);
return false; return false;
} }
} }

View File

@ -11,22 +11,12 @@ initializeTheme()
const queryClient = new QueryClient() const queryClient = new QueryClient()
// Register service worker
const updateSW = registerSW({ const updateSW = registerSW({
onNeedRefresh() { onNeedRefresh() {
if (confirm('New content available. Reload?')) { if (confirm('New content available. Reload?')) {
updateSW(true) 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( ReactDOM.createRoot(document.getElementById('root')!).render(