You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
using Justice.Helpers;
|
|
|
|
namespace Justice
|
|
{
|
|
public partial class AppShell : Shell
|
|
{
|
|
public Command LogoutCommand { get; }
|
|
public AppShell()
|
|
{
|
|
InitializeComponent();
|
|
|
|
Routing.RegisterRoute("LoginPage", typeof(Views.LoginPage));
|
|
Routing.RegisterRoute("DashboardPage", typeof(Views.DashboardPage));
|
|
Routing.RegisterRoute("ViewReportsPage", typeof(Views.EndUserReportsPage));
|
|
|
|
LogoutCommand = new Command(async () =>
|
|
{
|
|
AuthHelper.Logout();
|
|
await Shell.Current.GoToAsync("//LoginPage");
|
|
});
|
|
|
|
BindingContext = this;
|
|
|
|
|
|
}
|
|
|
|
protected override async void OnNavigating(ShellNavigatingEventArgs args)
|
|
{
|
|
base.OnNavigating(args);
|
|
|
|
// Check if user is authenticated
|
|
if (!AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("EndUserReportPage") || !AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("DashboardPage") || !AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("AuthorityReportsPage"))
|
|
{
|
|
args.Cancel(); // Prevent navigation
|
|
await Shell.Current.GoToAsync("//LoginPage");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|