forked from baron/baron-sso
log 추가
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
@@ -7,11 +8,23 @@ import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
import 'features/auth/presentation/login_screen.dart';
|
||||
import 'features/dashboard/presentation/dashboard_screen.dart';
|
||||
import 'core/services/auth_proxy_service.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
usePathUrlStrategy();
|
||||
|
||||
// 1. Global Error Handling
|
||||
FlutterError.onError = (details) {
|
||||
FlutterError.presentError(details);
|
||||
AuthProxyService.logError("FLUTTER_ERROR: ${details.exception}\n${details.stack}");
|
||||
};
|
||||
|
||||
PlatformDispatcher.instance.onError = (error, stack) {
|
||||
AuthProxyService.logError("PLATFORM_ERROR: $error\n$stack");
|
||||
return true;
|
||||
};
|
||||
|
||||
// Load Env (Handling error if missing for now)
|
||||
try {
|
||||
await dotenv.load(fileName: ".env");
|
||||
@@ -36,18 +49,29 @@ void main() async {
|
||||
// Router Configuration
|
||||
final _router = GoRouter(
|
||||
initialLocation: '/',
|
||||
debugLogDiagnostics: true, // Enable diagnostic logs
|
||||
routes: [
|
||||
GoRoute(path: '/', builder: (context, state) => const LoginScreen()),
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) {
|
||||
debugPrint("[Router] Navigating to root (LoginScreen)");
|
||||
return const LoginScreen();
|
||||
}
|
||||
),
|
||||
GoRoute(
|
||||
path: '/verify/:token',
|
||||
builder: (context, state) {
|
||||
final token = state.pathParameters['token'];
|
||||
debugPrint("[Router] Navigating to /verify with token: $token");
|
||||
return LoginScreen(verificationToken: token);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/dashboard',
|
||||
builder: (context, state) => const DashboardScreen(),
|
||||
builder: (context, state) {
|
||||
debugPrint("[Router] Navigating to /dashboard");
|
||||
return const DashboardScreen();
|
||||
},
|
||||
),
|
||||
],
|
||||
redirect: (context, state) {
|
||||
@@ -56,8 +80,16 @@ final _router = GoRouter(
|
||||
final path = state.uri.path;
|
||||
final isLoggingIn = path == '/' || path.startsWith('/verify/');
|
||||
|
||||
if (!isLoggedIn && !isLoggingIn) return '/';
|
||||
if (isLoggedIn && path == '/') return '/dashboard';
|
||||
debugPrint("[Router] Redirect check - Path: $path, IsLoggedIn: $isLoggedIn");
|
||||
|
||||
if (!isLoggedIn && !isLoggingIn) {
|
||||
debugPrint("[Router] Not logged in, redirecting to /");
|
||||
return '/';
|
||||
}
|
||||
if (isLoggedIn && path == '/') {
|
||||
debugPrint("[Router] Logged in, redirecting to /dashboard");
|
||||
return '/dashboard';
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user