Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RouteGuard not working in AutoTabsScaffold #1041

Closed
iamnabink opened this issue Apr 26, 2022 · 8 comments
Closed

RouteGuard not working in AutoTabsScaffold #1041

iamnabink opened this issue Apr 26, 2022 · 8 comments

Comments

@iamnabink
Copy link

iamnabink commented Apr 26, 2022

I am trying add auth guard for my AutoTabsScaffold [bottom nav] but it's not working, It's working in other navigation pages but not just inside my landing page [where AutoTabsScaffold| Bottom Nav resides] am I missing something here?

class LandingPage

   return AutoTabsScaffold(

      backgroundColor: Theme
          .of(context)
          .scaffoldBackgroundColor,
        routes: const [
          HomeRouter(),
          CategoryRouter(),
          OrderRouter(),
          ProfileRoute(),
      ],
      bottomNavigationBuilder: (_, tabsRouter) {return}

class auth guard:

class RouteGuard extends AutoRedirectGuard {
  final AuthService authService;

  RouteGuard(this.authService) {
    authService.addListener(() {
      if (!authService.authenticated) {
        // should be called when the logic effecting this guard changes
        // e.g when the user is no longer authenticated
        reevaluate();
      }
    });
  }

  @override
  void onNavigation(NavigationResolver resolver, StackRouter router) {
    if (authService.authenticated) return resolver.next();
    router.push(
      LoginRoute(
        onLoginCallback: (_) {
          resolver.next();
          router.removeLast();
        },
      ),
    );
  }
}

router.dart

@MaterialAutoRouter(
  replaceInRouteName: 'Page|Screen,Route',
  routes: <AutoRoute>[
    AutoRoute(page: OrderPreviewPage),
    AutoRoute(page: AddCardPage,),
    AutoRoute(page: PaymentPage,),
    AutoRoute(page: SplashPage, initial: true),
    AutoRoute(page: MyCartPage,),
    AutoRoute(page: IntroPage),
    AutoRoute(page: RegisterPage),
    AutoRoute(page: ProductDetailPage),
    AutoRoute(page: ProductListingPage),
    AutoRoute(page: CartSummaryPage,),
    AutoRoute(page: LoginPage, path: 'login'), //name: 'LoginRoute'
    AutoRoute(
      initial: true,
      page: LandingPage,
 //  guards: [RouteGuard],    //<------- here registered router guard working in [Tabscaffold]
      path: 'landing',
      children: [
        AutoRoute(
          path: '',
          name: 'homeRouter',
          page: HomePage,
        ),
        AutoRoute(
          path: 'category',
          name: 'categoryRouter',
          page: CategoryPage,
        ),
        AutoRoute(
          path: 'orders',
          name: 'orderRouter',
          page: OrdersPage,
        ),
        AutoRoute(
          path: 'profile',
          guards: [RouteGuard],    //<------- here registered router guard but not working in Tabscaffold page
          page: ProfilePage,
        ),
        // RedirectRoute(path: '*', redirectTo: ''),

      ],
    ),
  ],
)

@Milad-Akarie waiting for you answer :)

@iamnabink iamnabink changed the title auth guard not working in AutoTabsScaffold RouteGuard not working in AutoTabsScaffold Apr 26, 2022
@Milad-Akarie
Copy link
Owner

@iamnabink RouteGuards are not supported in TabsRouter for now.

@breucode
Copy link

breucode commented May 5, 2022

I just stumbled over the same problem. I would be very happy, if this will be a supported in the future.

@iamnabink
Copy link
Author

@iamnabink RouteGuards are not supported in TabsRouter for now.

would be very happy, if this will be a supported in the future.

@gabzim
Copy link

gabzim commented May 18, 2022

@Milad-Akarie do you mean that:
a. if we have 3 tabs for 3 different routes, we can't fire a guard when you switch tabs (eg to require face ID to change settings)? or
b. The Route containing the AutoTabScaffold cannot be guarded?

If a. then is there any workaround? My use case is that I want to use local_auth before letting the user change/see settings.

@wamynobe
Copy link

wamynobe commented Jan 5, 2024

Any update on this please?

@BriceFab
Copy link

BriceFab commented May 1, 2024

same

@nahiduzzaman-at-selise
Copy link

is it working now? as I see the issue is closed?

@wamynobe
Copy link

#1841 The author said It was planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants