Skip to content

Commit

Permalink
fix redirect bug, attempt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
WesselvanDam committed Sep 19, 2024
1 parent 0f9cab2 commit 51a4963
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
4 changes: 4 additions & 0 deletions lib/services/router/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';
import 'package:thank_you_token/main.dart';
import 'package:thank_you_token/providers/user_provider.dart';
import 'package:thank_you_token/services/router/routes.dart';
import 'package:thank_you_token/utils/extensions.dart';

final routerProvider = StateProvider<GoRouter>((ref) {
final isLoggedIn = ValueNotifier<bool>(initialLogIn);
Expand All @@ -29,6 +30,9 @@ final routerProvider = StateProvider<GoRouter>((ref) {
if (onPathRequiringAuth && !isLoggedIn.value) {
return LoginRoute().location;
}
if (state.fullPath?.isEmpty ?? true) {
return HomeRoute().location;
}
return null;
},
refreshListenable: isLoggedIn,
Expand Down
12 changes: 0 additions & 12 deletions lib/services/router/routes.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:thank_you_token/screens/Details/details_screen.dart';
Expand Down Expand Up @@ -58,16 +56,6 @@ class TokenDetailsRoute extends GoRouteData {

final String id;

// Redirect to the home page if the token is not found
@override
FutureOr<String?> redirect(BuildContext context, GoRouterState state) {
if (id.isEmpty ) {
return HomeRoute().location;
}
return null;
}


@override
Page buildPage(BuildContext context, GoRouterState state) {
return const DetailsPage(child: DetailsScreen());
Expand Down

0 comments on commit 51a4963

Please sign in to comment.