50 lines
1.4 KiB
Dart
50 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'package:energy_media/helpers/globals.dart';
|
|
import 'package:energy_media/pages/videos/videos_layout.dart';
|
|
import 'package:energy_media/pages/pages.dart';
|
|
import 'package:energy_media/services/navigation_service.dart';
|
|
|
|
/// The route configuration.
|
|
final GoRouter router = GoRouter(
|
|
debugLogDiagnostics: true,
|
|
navigatorKey: NavigationService.navigatorKey,
|
|
initialLocation: '/',
|
|
redirect: (BuildContext context, GoRouterState state) {
|
|
final bool loggedIn = currentUser != null;
|
|
final bool isLoggingIn = state.matchedLocation.contains('/login');
|
|
|
|
// If user is not logged in and not in the login page
|
|
if (!loggedIn && !isLoggingIn) return '/login';
|
|
|
|
//if user is logged in and in the login page
|
|
if (loggedIn && isLoggingIn) {
|
|
if (currentUser!.role.roleId == 14 || currentUser!.role.roleId == 13) {
|
|
return '/book_page_main';
|
|
} else {
|
|
return '/';
|
|
}
|
|
}
|
|
|
|
return null;
|
|
},
|
|
errorBuilder: (context, state) => const PageNotFoundPage(),
|
|
routes: <RouteBase>[
|
|
GoRoute(
|
|
path: '/',
|
|
name: 'root',
|
|
builder: (BuildContext context, GoRouterState state) {
|
|
return const VideosLayout();
|
|
},
|
|
),
|
|
GoRoute(
|
|
path: '/login',
|
|
name: 'login',
|
|
builder: (BuildContext context, GoRouterState state) {
|
|
return const LoginPage();
|
|
},
|
|
),
|
|
],
|
|
);
|