From 66106f20f62fa9c708e24ef0ed271445c72c587c Mon Sep 17 00:00:00 2001 From: Lectom C Han Date: Thu, 12 Feb 2026 11:41:16 +0900 Subject: [PATCH] =?UTF-8?q?[userfront]=20source=20=EA=B0=9C=EB=85=90?= =?UTF-8?q?=EC=82=AD=EC=A0=9C.=20redirect=20=EB=8F=99=EC=9E=91=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- userfront/Dockerfile | 2 +- .../services/web_auth_integration_web.dart | 29 +++++++++---------- .../auth/presentation/login_screen.dart | 9 ++++-- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/userfront/Dockerfile b/userfront/Dockerfile index 47052a28..1cebff7e 100644 --- a/userfront/Dockerfile +++ b/userfront/Dockerfile @@ -7,7 +7,7 @@ COPY . . # Get dependencies and build for web RUN flutter pub get RUN touch .env -RUN flutter build web --release --no-tree-shake-icons +RUN flutter build web --wasm --release --no-tree-shake-icons # Stage 2: Serve with Nginx FROM nginx:alpine diff --git a/userfront/lib/core/services/web_auth_integration_web.dart b/userfront/lib/core/services/web_auth_integration_web.dart index e07cb550..9b3b06db 100644 --- a/userfront/lib/core/services/web_auth_integration_web.dart +++ b/userfront/lib/core/services/web_auth_integration_web.dart @@ -61,10 +61,11 @@ void implSendLoginSuccess(String token) { } final message = {'type': 'LOGIN_SUCCESS', 'token': effectiveToken}; + final opener = html.window.opener; - if (html.window.opener != null) { + if (opener != null) { try { - html.window.opener!.postMessage(message, '*'); + opener.postMessage(message, '*'); debugPrint('Sent login success message to opener'); } catch (e) { debugPrint('Failed to postMessage: $e'); @@ -72,22 +73,20 @@ void implSendLoginSuccess(String token) { // Close the popup after a short delay to ensure message sending Timer(const Duration(milliseconds: 500), () { - html.window.close(); + try { + html.window.close(); + } catch (e) { + debugPrint('Failed to close window: $e'); + } }); - } else { - // Should not happen given isPopup check, but as fallback: - debugPrint('No opener found during popup flow.'); + return; } + + // No opener and no redirect: fall back to local navigation + debugPrint('No opener found. Redirecting to /.'); + html.window.location.href = '/'; } bool implIsPopup() { - if (html.window.opener != null) return true; - - // Fallback: Check query parameters for integration source - final uri = Uri.base; - if (uri.queryParameters['source'] == 'adminfront') return true; - - // Manual parse fallback for cases where Uri.base might miss params due to hash routing - final search = html.window.location.search; - return search != null && search.contains('source=adminfront'); + return html.window.opener != null; } diff --git a/userfront/lib/features/auth/presentation/login_screen.dart b/userfront/lib/features/auth/presentation/login_screen.dart index c738d284..c7a3e6e8 100644 --- a/userfront/lib/features/auth/presentation/login_screen.dart +++ b/userfront/lib/features/auth/presentation/login_screen.dart @@ -1149,8 +1149,13 @@ class _LoginScreenState extends ConsumerState } } - if (WebAuthIntegration.isPopup() || - (_redirectUrl != null && _redirectUrl!.isNotEmpty)) { + final uri = Uri.base; + final redirectParam = + uri.queryParameters['redirect_uri'] ?? uri.queryParameters['redirect_url']; + final hasRedirectParam = + redirectParam != null && redirectParam.isNotEmpty; + + if (WebAuthIntegration.isPopup() || hasRedirectParam) { debugPrint( "[Auth] External integration detected (popup or redirect). Notifying...", );