From 14af8f3fa9c6283540f3b8408a794c01e239a5ac Mon Sep 17 00:00:00 2001 From: Lectom C Han Date: Fri, 13 Feb 2026 12:35:08 +0900 Subject: [PATCH] fix(userfront): restore web auth redirect variables after merge regression --- .../services/web_auth_integration_web.dart | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/userfront/lib/core/services/web_auth_integration_web.dart b/userfront/lib/core/services/web_auth_integration_web.dart index 493d17e7..9b3b06db 100644 --- a/userfront/lib/core/services/web_auth_integration_web.dart +++ b/userfront/lib/core/services/web_auth_integration_web.dart @@ -3,16 +3,32 @@ import 'dart:async'; import 'dart:html' as html; import 'package:flutter/foundation.dart'; +import 'auth_token_store.dart'; void implSendLoginSuccess(String token) { - final message = {'type': 'LOGIN_SUCCESS', 'token': token}; - - if (html.window.opener != null) { - try { - html.window.opener!.postMessage(message, '*'); - debugPrint('Sent login success message to opener'); - } catch (e) { - debugPrint('Failed to postMessage: $e'); + var effectiveToken = token; + if (effectiveToken.isEmpty) { + effectiveToken = AuthTokenStore.getToken() ?? ""; + } + + final fullUrl = html.window.location.href; + final uri = Uri.base; + + // Try to find redirect_uri from standard parsing first, then manual string search + String? redirectUri = + uri.queryParameters['redirect_uri'] ?? + uri.queryParameters['redirect_url']; + + if (redirectUri == null) { + // Manual fallback for cases where Uri.base misses params + final searchParams = html.window.location.search; + if (searchParams != null && searchParams.isNotEmpty) { + final sUri = Uri.parse( + '?${searchParams.startsWith('?') ? searchParams.substring(1) : searchParams}', + ); + redirectUri = + sUri.queryParameters['redirect_uri'] ?? + sUri.queryParameters['redirect_url']; } } @@ -63,9 +79,7 @@ void implSendLoginSuccess(String token) { 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