go_guardian 0.2.3
go_guardian: ^0.2.3 copied to clipboard
NestJS-style declarative route guards for GoRouter. Declare guards at the route level, inherit through shells, compose with existing redirect logic.
0.2.1 #
Bug Fixes #
GuardedShellRoutenow actually propagates guards to child routes. Previously, shell guards were stored as data but never evaluated on childGuardedRoutes. Guards are now reconstructed at construction time — shell guards are prepended to each child's own guards, andGuardMetais merged. Nested shells accumulate correctly.GuardedRoute.existingRedirectis now a stored field, so shell route reconstruction can recover it during guard propagation.
Improvements #
- Example app now has a working onboarding flow: login → OnboardingGuard redirects to
/onboarding→ complete → home. - Expanded test coverage for shell guard inheritance (7 new tests: inherit, allow, combine, nested, meta merge, plain GoRoute opt-out).
- Removed dead
GuardRegistryclass (guard inheritance is now handled at construction time).
0.2.0 #
Universal State Management Support #
.stateless()factories on all 4 built-in guards (AuthGuard,RoleGuard,OnboardingGuard,MaintenanceGuard). Usebool Function()instead ofbool Function(BuildContext)— works with GetX, Riverpodref, singletons, Signals, or any approach that doesn't needBuildContext.
New Features #
- Re-exports
go_router— one import (package:go_guardian/go_guardian.dart) gives you everything. No need to addgo_routerto your pubspec separately. DiscardedRoute— inverse ofGuardedRoute. Redirects AWAY when a condition IS met. Classic use case:/loginredirects to/homewhen user is already authenticated. Both context-aware and.stateless()constructors.GuardRefreshNotifier— composes multipleListenables andStreams into oneListenableforGoRouter.refreshListenable. Factory constructors:.from(),.fromStreams().GuardObserver/DebugGuardObserver— guard evaluation lifecycle events. SetGoGuardian.observer = DebugGuardObserver()to log every guard check with timing.GuardTestHarness— unit test guards without a widget tree.check(),checkAll(), plus builderswithMeta(),withPath(),withQueryParams().
Example #
- Comprehensive example app demonstrating all guard features: inheritance, onboarding flow, DiscardedRoute, maintenance mode, role-based access, custom guards, guard composition, and brownfield migration.
Internal #
GuardResolveremitsGuardEvents with per-guard timing viaStopwatch.
0.1.0 #
- Initial release
RouteGuardabstract base class with&,|,~composition operatorsGuardedRoute— GoRoute with declarative guard supportGuardedShellRoute— ShellRoute with guard inheritanceGuardChain— brownfield migration support for existing redirect logicGuardMeta— typed metadata container for per-route guard configuration- Built-in guards:
AuthGuard,RoleGuard,OnboardingGuard,MaintenanceGuard - Guard priority ordering
- Deep link preservation on
AuthGuard - Example app