forked from baron/baron-sso
fix(userfront): restore web auth redirect variables after merge regression
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user