Files
softplayer-web/lib/core/router/app_router.dart
Nikolai Rodionov 09df205fdb
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Start writing the web app
Signed-off-by: Nikolai Rodionov <allanger@posteo.com>
2026-05-27 16:08:53 +02:00

31 lines
1.1 KiB
Dart

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:softplayer_web/core/tokens/application/tokens_application.dart';
import 'package:softplayer_web/features/authorization/application/authorization_application.dart';
import 'package:softplayer_web/features/authorization/presentation/authorization_page.dart';
import 'package:softplayer_web/features/dashboard/presentation/dashboard_page.dart';
final goRouterProvider = Provider<GoRouter>((ref) {
final authState = ref.watch(authorizationControllerProvider);
final _tokenCtrl = ref.watch(tokensControllerProvider);
// If not authorized, redirect to the auth page, otherwise dashboard
return GoRouter(
initialLocation: '/',
redirect: (context, state) {
final isAuthorized = authState.requireValue.isAuthorized;
if (!isAuthorized) {
return "/auth";
}
return "/";
},
routes: [
GoRoute(path: '/', builder: (context, state) => const DashboardPage()),
GoRoute(
path: '/auth',
builder: (context, state) => const AuthorizationPage(),
),
],
);
});