canActivate method

  1. @override
Future<bool> canActivate(
  1. String path,
  2. ModularRoute route
)

Returns a FutureOr. If true, allow the route to continue processing. If it is false, the Guard will try to redirect the route. If there is no redirect then an error will be thrown GuardedRouteException.

Implementation

@override
Future<bool> canActivate(String path, ModularRoute route) async {
  final auth = Modular.get<AuthRepository>();

  await Future.doWhile(() async {
    await Future.delayed(const Duration(milliseconds: 100));
    return auth.state.isLoading;
  });

  return auth.isAuthenticated;
}