Start writing the web app
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Signed-off-by: Nikolai Rodionov <allanger@posteo.com>
This commit was merged in pull request #5.
This commit is contained in:
30
lib/core/router/app_router.dart
Normal file
30
lib/core/router/app_router.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
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(),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user