Last active
August 4, 2021 12:56
-
-
Save BrianMwas/8a3dc0366c3cb987a79b6e37ef76ef85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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