diff --git a/AppShell.xaml b/AppShell.xaml index b5ce1b2..2d127ce 100644 --- a/AppShell.xaml +++ b/AppShell.xaml @@ -7,7 +7,9 @@ Shell.FlyoutBehavior="Flyout" Title="Justice"> - - - + + + + + diff --git a/AppShell.xaml.cs b/AppShell.xaml.cs index d89c2e3..5d609f4 100644 --- a/AppShell.xaml.cs +++ b/AppShell.xaml.cs @@ -1,10 +1,39 @@ -namespace Justice +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.ViewReportsPage)); + + 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("ViewReportsPage") || !AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("DashboardPage")) + { + args.Cancel(); // Prevent navigation + await Shell.Current.GoToAsync("//LoginPage"); + } } } } diff --git a/Views/DashboardPage.xaml b/Views/DashboardPage.xaml index 0a6e931..2b4d2c6 100644 --- a/Views/DashboardPage.xaml +++ b/Views/DashboardPage.xaml @@ -3,8 +3,14 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Justice.Views.DashboardPage" Title="DashboardPage" BackgroundColor="WhiteSmoke"> + + +