using Justice.Helpers; using Justice.Services; using Justice.Models; using Microsoft.Maui.Controls.Maps; using Microsoft.Maui.Maps; 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"); } } } }