From 3aebe7e14dba6fe10d29fc24e3a0ed7e502a9079 Mon Sep 17 00:00:00 2001 From: Lars Refsgaard <1552887+LarsRefsgaard@users.noreply.github.com> Date: Thu, 3 Aug 2023 10:52:21 +0200 Subject: [PATCH] Update route redirects in CarpStudyApp Detailed Description: Reworked routing redirects for login, consent, task, and invitation pages in CarpStudyApp. Now the routing considers if a user is authenticated and properly handles redirects to the consent or tasks pages. Furthermore, if a study ID is not present, redirections to the invitation page have been implemented. If a user is unauthenticated, they'll be redirected to the login page. --- lib/carp_study_app.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/carp_study_app.dart b/lib/carp_study_app.dart index ee9f2430..a2ab6be4 100644 --- a/lib/carp_study_app.dart +++ b/lib/carp_study_app.dart @@ -36,8 +36,9 @@ class CarpStudyAppState extends State { GoRoute( path: '/', parentNavigatorKey: _shellNavigatorKey, - redirect: (context, state) => - bloc.hasInformedConsentBeenAccepted ? '/tasks' : '/consent', + redirect: (context, state) => !CarpService().authenticated + ? '/login' + : (bloc.hasInformedConsentBeenAccepted ? '/tasks' : '/consent'), ), GoRoute( path: '/tasks', @@ -103,8 +104,9 @@ class CarpStudyAppState extends State { GoRoute( path: '/consent', parentNavigatorKey: _rootNavigatorKey, - redirect: (context, state) => - bloc.studyId == null ? '/invitations' : null, + redirect: (context, state) => bloc.hasInformedConsentBeenAccepted + ? '/tasks' + : (bloc.studyId == null ? '/invitations' : null), builder: (context, state) => InformedConsentPage( bloc.data.informedConsentViewModel, ), @@ -116,6 +118,7 @@ class CarpStudyAppState extends State { GoRoute( path: '/login', parentNavigatorKey: _rootNavigatorKey, + redirect: (context, state) => CarpService().authenticated ? '/' : null, builder: (context, state) => LoginPage( bloc.data.loginPageViewModel, ), @@ -136,7 +139,9 @@ class CarpStudyAppState extends State { GoRoute( path: '/invitations', parentNavigatorKey: _rootNavigatorKey, - redirect: (context, state) => bloc.user == null ? '/login' : null, + redirect: (context, state) => bloc.studyId != null + ? '/consent' + : (bloc.user == null ? '/login' : null), builder: (context, state) => InvitationListPage(bloc.data.invitationsListViewModel), ),