Skip to content

Commit

Permalink
Use a GlobalKey to ensure GoRouter doesn't rebuild when watching auth…
Browse files Browse the repository at this point in the history
…StateChangesProvider
  • Loading branch information
bizz84 committed Dec 18, 2023
1 parent ca3534d commit 9b45671
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/src/routing/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ enum AppRoute {
@riverpod
// ignore: unsupported_provider_value
GoRouter goRouter(GoRouterRef ref) {
final authRepository = ref.watch(authRepositoryProvider);
final onboardingRepository =
ref.watch(onboardingRepositoryProvider).requireValue;
final authState = ref.watch(authStateChangesProvider);
return GoRouter(
initialLocation: '/signIn',
// Use a GlobalKey to ensure GoRouter doesn't rebuild when watching the providers above
// For more details, see:
// https://github.com/lucavenir/go_router_riverpod
// https://github.com/flutter/flutter/issues/116651
navigatorKey: _rootNavigatorKey,
debugLogDiagnostics: true,
redirect: (context, state) {
Expand All @@ -58,7 +62,8 @@ GoRouter goRouter(GoRouterRef ref) {
return '/onboarding';
}
}
final isLoggedIn = authRepository.currentUser != null;
final user = authState.value;
final isLoggedIn = user != null;
if (isLoggedIn) {
if (path.startsWith('/signIn')) {
return '/jobs';
Expand All @@ -72,7 +77,6 @@ GoRouter goRouter(GoRouterRef ref) {
}
return null;
},
refreshListenable: GoRouterRefreshStream(authRepository.authStateChanges()),
routes: [
GoRoute(
path: '/onboarding',
Expand Down

0 comments on commit 9b45671

Please sign in to comment.