From 181156de102d691f9c5632d07fb2059a54ff41c5 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Wed, 8 Jul 2026 12:46:42 -0400 Subject: [PATCH] fix: prevent infinite reload loop in OAuth deep link handling and clean up comments in LoginView --- src/CapacitorListener.js | 15 +++++++++++++-- src/views/Authorization/LoginView.jsx | 1 - 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/CapacitorListener.js b/src/CapacitorListener.js index c8fdf21..8150569 100644 --- a/src/CapacitorListener.js +++ b/src/CapacitorListener.js @@ -48,6 +48,16 @@ const handleOAuthDeepLink = async url => { const state = urlObj.searchParams.get('state') if (code && state) { + // getLaunchUrl() persists across every WebView reload caused by + // window.location.href. If we're already on the OAuth handler page with + // the same code, skip re-navigating to avoid an infinite reload loop. + const currentCode = new URLSearchParams(window.location.search).get( + 'code', + ) + if (window.location.pathname === '/auth/oauth2' && currentCode === code) { + return + } + // Store the OAuth params for the app to pick up await Preferences.set({ key: 'oauth_callback', @@ -258,7 +268,7 @@ const registerCapacitorListeners = () => { console.log('[NFC] appUrlOpen:', event.url) handleUrlOpen(event.url) }) - + mobileApp.addListener('appStateChange', ({ isActive }) => { focusManager.setFocused(isActive) }) @@ -277,5 +287,6 @@ const registerCapacitorListeners = () => { export { registerCapacitorListeners, - pushNotificationListenerRegistration as registerPushNotifications, + pushNotificationListenerRegistration as registerPushNotifications } + diff --git a/src/views/Authorization/LoginView.jsx b/src/views/Authorization/LoginView.jsx index 108ff14..48a3a92 100644 --- a/src/views/Authorization/LoginView.jsx +++ b/src/views/Authorization/LoginView.jsx @@ -310,7 +310,6 @@ const LoginView = () => { const state = generateRandomState() if (Capacitor.isNativePlatform()) { - // For mobile devices, use a custom URL scheme for the redirect const redirectUri = 'donetick://auth/oauth2' const params = new URLSearchParams({