From 516a7b36355d6da0c7465676fb02f0abc5139cd5 Mon Sep 17 00:00:00 2001 From: chan Date: Wed, 11 Feb 2026 15:50:13 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20SSO=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=EC=8B=9C=20adminfront=EB=A1=9C=EC=9D=98?= =?UTF-8?q?=20=EB=A6=AC=EB=8B=A4=EC=9D=B4=EB=A0=89=EC=85=98=20=EB=B0=8F=20?= =?UTF-8?q?postMessage=20=ED=9D=90=EB=A6=84=20=EA=B0=95=ED=99=94=20#243?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/web_auth_integration_web.dart | 10 ++++++-- .../auth/presentation/login_screen.dart | 23 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/userfront/lib/core/services/web_auth_integration_web.dart b/userfront/lib/core/services/web_auth_integration_web.dart index ab5c0a3d..2ecaf079 100644 --- a/userfront/lib/core/services/web_auth_integration_web.dart +++ b/userfront/lib/core/services/web_auth_integration_web.dart @@ -3,8 +3,14 @@ import 'dart:async'; import 'dart:html' as html; import 'package:flutter/foundation.dart'; +import 'auth_token_store.dart'; void implSendLoginSuccess(String token) { + var effectiveToken = token; + if (effectiveToken.isEmpty) { + effectiveToken = AuthTokenStore.getToken() ?? ""; + } + final uri = Uri.parse(html.window.location.href); final redirectUri = uri.queryParameters['redirect_uri']; @@ -12,7 +18,7 @@ void implSendLoginSuccess(String token) { // Redirection flow final target = Uri.parse(redirectUri); final query = Map.from(target.queryParameters); - query['token'] = token; + query['token'] = effectiveToken; final finalUri = target.replace(queryParameters: query); debugPrint('Redirecting to: ${finalUri.toString()}'); @@ -20,7 +26,7 @@ void implSendLoginSuccess(String token) { return; } - final message = {'type': 'LOGIN_SUCCESS', 'token': token}; + final message = {'type': 'LOGIN_SUCCESS', 'token': effectiveToken}; if (html.window.opener != null) { try { diff --git a/userfront/lib/features/auth/presentation/login_screen.dart b/userfront/lib/features/auth/presentation/login_screen.dart index 82a3ae6a..f4e12b3f 100644 --- a/userfront/lib/features/auth/presentation/login_screen.dart +++ b/userfront/lib/features/auth/presentation/login_screen.dart @@ -163,6 +163,16 @@ class _LoginScreenState extends ConsumerState return; } } + + final token = AuthTokenStore.getToken(); + if (token != null && token.isNotEmpty) { + if (WebAuthIntegration.isPopup() || (_redirectUrl != null && _redirectUrl!.isNotEmpty)) { + debugPrint("[Auth] Cookie session with external integration. Notifying..."); + WebAuthIntegration.sendLoginSuccess(token); + return; + } + } + if (mounted) { context.go('/'); } @@ -1123,17 +1133,10 @@ class _LoginScreenState extends ConsumerState } } - if (WebAuthIntegration.isPopup()) { - debugPrint("[Auth] Popup detected. Notifying opener and attempting to close."); + if (WebAuthIntegration.isPopup() || (_redirectUrl != null && _redirectUrl!.isNotEmpty)) { + debugPrint("[Auth] External integration detected (popup or redirect). Notifying..."); WebAuthIntegration.sendLoginSuccess(token); - return; // Stop here for popups - } - - if (_redirectUrl != null && _redirectUrl!.isNotEmpty) { - debugPrint("[Auth] Redirecting standalone window to: $_redirectUrl"); - final target = "$_redirectUrl?token=$token"; - launchUrlString(target, webOnlyWindowName: '_self'); - return; + return; } debugPrint("[Auth] Login success. Navigating to root.");