Skip to content

Commit

Permalink
examples/authentication_bloc: [update] usage regarding new guarding l…
Browse files Browse the repository at this point in the history
…ogic
  • Loading branch information
slovnicki committed Jan 26, 2022
1 parent f6ca1f3 commit df194e8
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions examples/authentication_bloc/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class MyApp extends StatelessWidget {
BeamGuard(
pathPatterns: ['/logged_in_page'],
check: (context, state) =>
context.select((AuthenticationBloc auth) => auth.isAuthenticated()),
context.read<AuthenticationBloc>().isAuthenticated(),
beamToNamed: (_, __) => '/login',
),
// Guard /login by beaming to /logged_in_page if the user is authenticated:
BeamGuard(
pathPatterns: ['/login'],
check: (context, state) => context
.select((AuthenticationBloc auth) => !auth.isAuthenticated()),
check: (context, state) =>
!context.read<AuthenticationBloc>().isAuthenticated(),
beamToNamed: (_, __) => '/logged_in_page',
),
],
Expand All @@ -67,14 +67,18 @@ class MyApp extends StatelessWidget {
authenticationRepository: authenticationRepository,
userRepository: userRepository,
),
child: BeamerProvider(
routerDelegate: routerDelegate,
child: MaterialApp.router(
debugShowCheckedModeBanner: false,
routerDelegate: routerDelegate,
routeInformationParser: BeamerParser(),
),
),
child: Builder(builder: (context) {
return BlocListener<AuthenticationBloc, AuthenticationState>(
listener: (context, state) {
routerDelegate.update();
},
child: MaterialApp.router(
debugShowCheckedModeBanner: false,
routerDelegate: routerDelegate,
routeInformationParser: BeamerParser(),
),
);
}),
),
);
}
Expand Down

0 comments on commit df194e8

Please sign in to comment.