GoRouter goRouter()

in ui/lib/routing/app_router.dart [49:152]


GoRouter goRouter(GoRouterRef ref) {
  final authFirebaseState = ref.watch(authProvider);
  final authState = ref.watch(googleAuthProvider);
  final authRepo = ref.watch(authRepositoryProvider);

  return GoRouter(
    navigatorKey: _key,
    initialLocation: '/login',
    redirect: (context, state) async {

      if (authState.valueOrNull == null) {
        if (state.location == "/login")
          return null;
        else
          await authRepo.signInWithGoogle();
      }

      if (authState.isLoading || authState.hasError) return null;

      final isAuth = authState.valueOrNull != null;

      final isLoggingIn = state.location == '/login';
      if (isLoggingIn) return isAuth ? '/home' : null;

      return isAuth ? null : '/login';
    },
    routes: [
      GoRoute(
        path: '/home',
        name: 'home',
        pageBuilder: (context, state) => buildPageWithDefaultTransition<void>(
          context: context,
          state: state,
          child: HomeScreen(),
        ),
      ),
      GoRoute(
        path: '/example',
        name: 'example',
        pageBuilder: (context, state) => buildPageWithDefaultTransition<void>(
          context: context,
          state: state,
          child: ExampleScreen(),
        ),
      ),
      GoRoute(
        path: '/login',
        name: 'login',
        pageBuilder: (context, state) => buildPageWithDefaultTransition<void>(
          context: context,
          state: state,
          child: SignInScreen(),
        ),
      ),
      GoRoute(
        path: '/settings',
        name: 'settings',
        pageBuilder: (context, state) => buildPageWithDefaultTransition<void>(
          context: context,
          state: state,
          child: SettingsScreen(),
        ),
      ),
      GoRoute(
        path: '/services',
        name: 'services',
        pageBuilder: (context, state) => buildPageWithDefaultTransition<void>(
          context: context,
          state: state,
          child: MyServicesScreen(),
        ),
      ),
      GoRoute(
          path: '/service/:serviceDocId',
          name: 'service',
          pageBuilder: (context, state) {
            final serviceID = state.params['serviceDocId']!;
            return buildPageWithDefaultTransition<void>(
              context: context,
              state: state,
              child: ServiceDetail(serviceID),
            );
          }),
      GoRoute(
        path: '/catalog',
        name: 'catalog',
        pageBuilder: (context, state) => buildPageWithDefaultTransition<void>(
          context: context,
          state: state,
          child: CatalogScreen(queryParams: state.queryParams),
        ),
      ),
      GoRoute(
        path: '/workstations',
        name: 'workstations',
        pageBuilder: (context, state) => buildPageWithDefaultTransition<void>(
          context: context,
          state: state,
          child: MyWorkstationsScreen(),
        ),
      ),
    ],
  );
}