forked from baron/baron-sso
71 lines
1.9 KiB
Dart
71 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:descope/descope.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'features/auth/presentation/login_screen.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// Load Env (Handling error if missing for now)
|
|
try {
|
|
await dotenv.load(fileName: ".env");
|
|
} catch (e) {
|
|
debugPrint("Warning: .env file not found.");
|
|
}
|
|
|
|
// Initialize Descope
|
|
final projectId = dotenv.env['DESCOPE_PROJECT_ID'] ?? 'your-project-id';
|
|
Descope.setup(projectId);
|
|
|
|
// Load saved session if any
|
|
await Descope.sessionManager.loadSession();
|
|
|
|
runApp(const ProviderScope(child: BaronSSOApp()));
|
|
}
|
|
|
|
// Router Configuration
|
|
final _router = GoRouter(
|
|
initialLocation: '/',
|
|
routes: [
|
|
GoRoute(path: '/', builder: (context, state) => const LoginScreen()),
|
|
GoRoute(
|
|
path: '/dashboard',
|
|
builder: (context, state) =>
|
|
const Scaffold(body: Center(child: Text("Dashboard Placeholder"))),
|
|
),
|
|
],
|
|
redirect: (context, state) {
|
|
final isLoggedIn =
|
|
Descope.sessionManager.session?.refreshToken.isExpired == false;
|
|
final isLoggingIn = state.uri.toString() == '/';
|
|
|
|
if (!isLoggedIn && !isLoggingIn) return '/';
|
|
if (isLoggedIn && isLoggingIn) return '/dashboard';
|
|
|
|
return null;
|
|
},
|
|
);
|
|
|
|
class BaronSSOApp extends StatelessWidget {
|
|
const BaronSSOApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp.router(
|
|
title: 'Baron SSO',
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: const Color(0xFF1A1F2C), // Dark Navy/Black base
|
|
brightness: Brightness.light,
|
|
),
|
|
useMaterial3: true,
|
|
textTheme: GoogleFonts.interTextTheme(),
|
|
),
|
|
routerConfig: _router,
|
|
);
|
|
}
|
|
}
|