forked from baron/baron-sso
userfront 로그인 후 /dashboard로 이동하게 변경
This commit is contained in:
@@ -20,6 +20,8 @@ import 'features/profile/presentation/pages/profile_page.dart';
|
||||
import 'core/services/auth_proxy_service.dart';
|
||||
import 'core/services/auth_token_store.dart';
|
||||
import 'core/services/logger_service.dart';
|
||||
import 'core/services/null_check_recovery.dart';
|
||||
import 'core/services/web_window.dart';
|
||||
import 'core/notifiers/auth_notifier.dart';
|
||||
import 'core/i18n/locale_gate.dart';
|
||||
import 'core/i18n/locale_registry.dart';
|
||||
@@ -31,6 +33,29 @@ import 'i18n.dart';
|
||||
|
||||
final _log = Logger('Main');
|
||||
|
||||
void _attemptRecoveryFromNullCheck({
|
||||
required Object exception,
|
||||
StackTrace? stackTrace,
|
||||
}) {
|
||||
final uri = Uri.base;
|
||||
final target = computeNullCheckRecoveryTarget(
|
||||
exception: exception,
|
||||
uri: uri,
|
||||
preferredLocaleCode: resolvePreferredLocaleCode(),
|
||||
);
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
final path = uri.path;
|
||||
|
||||
AuthProxyService.logError(
|
||||
'RECOVERY_NAV_NULL_CHECK path=$path target=$target uri=$uri',
|
||||
error: exception,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
webWindow.redirectTo(target);
|
||||
}
|
||||
|
||||
Future<void> _loadBundledFonts() async {
|
||||
const family = 'NotoSansKR';
|
||||
final loader = FontLoader(family);
|
||||
@@ -57,11 +82,16 @@ void main() async {
|
||||
AuthProxyService.logError(
|
||||
"FLUTTER_ERROR: ${details.exception}\n${details.stack}",
|
||||
);
|
||||
_attemptRecoveryFromNullCheck(
|
||||
exception: details.exception,
|
||||
stackTrace: details.stack,
|
||||
);
|
||||
};
|
||||
|
||||
PlatformDispatcher.instance.onError = (error, stack) {
|
||||
_log.severe("PLATFORM_ERROR", error, stack);
|
||||
AuthProxyService.logError("PLATFORM_ERROR: $error\n$stack");
|
||||
_attemptRecoveryFromNullCheck(exception: error, stackTrace: stack);
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -107,6 +137,15 @@ final _router = GoRouter(
|
||||
debugLogDiagnostics: !kReleaseMode,
|
||||
refreshListenable: AuthNotifier.instance,
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
redirect: (context, state) {
|
||||
return buildLocalizedHomePath(
|
||||
state.uri,
|
||||
preferredLocaleCode: resolvePreferredLocaleCode(),
|
||||
);
|
||||
},
|
||||
),
|
||||
ShellRoute(
|
||||
builder: (context, state, child) {
|
||||
final localeCode =
|
||||
@@ -116,10 +155,25 @@ final _router = GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/:locale',
|
||||
// Note: Removed direct builder here to prevent interference with sub-routes
|
||||
redirect: (context, state) {
|
||||
// /{locale} 진입은 화면 렌더링 없이 단일 목적지로만 보냅니다.
|
||||
if (state.uri.pathSegments.length != 1) {
|
||||
return null;
|
||||
}
|
||||
final rawLocale = state.pathParameters['locale'];
|
||||
final localeCode = normalizeLocaleCode(rawLocale);
|
||||
final token = AuthTokenStore.getToken();
|
||||
final isLoggedIn =
|
||||
(token != null && token.isNotEmpty) ||
|
||||
AuthTokenStore.usesCookie();
|
||||
if (!isLoggedIn) {
|
||||
return buildSigninRedirectPath(localeCode, state.uri);
|
||||
}
|
||||
return '/$localeCode/dashboard';
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '', // Matches /:locale
|
||||
path: 'dashboard',
|
||||
builder: (context, state) {
|
||||
return const DashboardScreen();
|
||||
},
|
||||
@@ -299,9 +353,16 @@ final _router = GoRouter(
|
||||
}
|
||||
|
||||
if (!isLoggedIn) {
|
||||
if (path == '/') {
|
||||
return '/$requestedLocale/signin';
|
||||
}
|
||||
return buildSigninRedirectPath(requestedLocale, uri);
|
||||
}
|
||||
|
||||
if (path == '/') {
|
||||
return '/$requestedLocale/dashboard';
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
);
|
||||
@@ -311,11 +372,21 @@ class BaronSSOApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localization = EasyLocalization.of(context);
|
||||
final supportedLocales =
|
||||
localization?.supportedLocales ??
|
||||
LocaleRegistry.supportedLocaleCodes
|
||||
.map((code) => Locale(code))
|
||||
.toList(growable: false);
|
||||
final delegates = localization?.delegates ?? const [];
|
||||
final locale =
|
||||
localization?.currentLocale ?? Locale(resolvePreferredLocaleCode());
|
||||
|
||||
return MaterialApp.router(
|
||||
title: tr('ui.userfront.app_title'),
|
||||
localizationsDelegates: context.localizationDelegates,
|
||||
supportedLocales: context.supportedLocales,
|
||||
locale: context.locale,
|
||||
localizationsDelegates: delegates,
|
||||
supportedLocales: supportedLocales,
|
||||
locale: locale,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: const Color(0xFF1A1F2C), // Dark Navy/Black base
|
||||
|
||||
Reference in New Issue
Block a user