Skip to content

Instantly share code, notes, and snippets.

@BrianMwas
Last active August 4, 2021 12:56
Show Gist options
  • Save BrianMwas/8a3dc0366c3cb987a79b6e37ef76ef85 to your computer and use it in GitHub Desktop.
Save BrianMwas/8a3dc0366c3cb987a79b6e37ef76ef85 to your computer and use it in GitHub Desktop.
class AuthGuard extends GetMiddleware {
// Get the auth service
final authService = Get.find<AuthService>();
// The default is 0 but you can update it to any number. Please ensure you match the priority based
// on the number of guards you have.
@override
int? get priority => 1;
@override
RouteSettings? redirect(String? route) {
// Navigate to login if client is not authenticated other wise continue
if (authService.isAuthenticated) return RouteSettings(name: AppLinks.LOGIN);
return RouteSettings(name: AppLinks.DASHBOARD);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment