redirect method

  1. @override
String? redirect(
  1. BuildContext context,
  2. GoRouterState state
)
override

An optional redirect function for this route.

Subclasses must override one of build, buildPage, or redirect.

Corresponds to GoRoute.redirect.

Implementation

@override
String? redirect(BuildContext context, GoRouterState state) {
  final user = ProviderScope.containerOf(context).read(currentUserProvider)!;
  // If user is not an admin, redirect to home
  if (!user.customClaims.admin) {
    return const HomeRoute().location;
  }
  return null;
}