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.
Seekers/AppShell.xaml.cs

40 lines
1.2 KiB

6 months ago
using Justice.Helpers;
namespace Justice
{
public partial class AppShell : Shell
{
6 months ago
public Command LogoutCommand { get; }
public AppShell()
{
InitializeComponent();
6 months ago
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");
}
}
}
}