Skip to content

Commit

Permalink
Update route redirects in CarpStudyApp
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LarsRefsgaard committed Aug 3, 2023
1 parent adfc16c commit 3aebe7e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/carp_study_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class CarpStudyAppState extends State<CarpStudyApp> {
GoRoute(
path: '/',
parentNavigatorKey: _shellNavigatorKey,
redirect: (context, state) =>
bloc.hasInformedConsentBeenAccepted ? '/tasks' : '/consent',
redirect: (context, state) => !CarpService().authenticated
? '/login'
: (bloc.hasInformedConsentBeenAccepted ? '/tasks' : '/consent'),
),
GoRoute(
path: '/tasks',
Expand Down Expand Up @@ -103,8 +104,9 @@ class CarpStudyAppState extends State<CarpStudyApp> {
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,
),
Expand All @@ -116,6 +118,7 @@ class CarpStudyAppState extends State<CarpStudyApp> {
GoRoute(
path: '/login',
parentNavigatorKey: _rootNavigatorKey,
redirect: (context, state) => CarpService().authenticated ? '/' : null,
builder: (context, state) => LoginPage(
bloc.data.loginPageViewModel,
),
Expand All @@ -136,7 +139,9 @@ class CarpStudyAppState extends State<CarpStudyApp> {
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),
),
Expand Down

0 comments on commit 3aebe7e

Please sign in to comment.