mirror of
https://github.com/bitwarden/mobile
synced 2026-01-02 08:33:17 +00:00
Centralized logout into a message subscription in app class. Logout when API results are forbidden or unauthorized.
This commit is contained in:
@@ -13,6 +13,7 @@ using Bit.App.Controls;
|
||||
using Plugin.Connectivity.Abstractions;
|
||||
using System.Net;
|
||||
using Acr.UserDialogs;
|
||||
using PushNotification.Plugin.Abstractions;
|
||||
|
||||
namespace Bit.App
|
||||
{
|
||||
@@ -25,6 +26,7 @@ namespace Bit.App
|
||||
private readonly IAuthService _authService;
|
||||
private readonly IFingerprint _fingerprint;
|
||||
private readonly ISettings _settings;
|
||||
private readonly IPushNotification _pushNotification;
|
||||
|
||||
public App(
|
||||
IAuthService authService,
|
||||
@@ -33,7 +35,8 @@ namespace Bit.App
|
||||
IDatabaseService databaseService,
|
||||
ISyncService syncService,
|
||||
IFingerprint fingerprint,
|
||||
ISettings settings)
|
||||
ISettings settings,
|
||||
IPushNotification pushNotification)
|
||||
{
|
||||
_databaseService = databaseService;
|
||||
_connectivity = connectivity;
|
||||
@@ -42,6 +45,7 @@ namespace Bit.App
|
||||
_authService = authService;
|
||||
_fingerprint = fingerprint;
|
||||
_settings = settings;
|
||||
_pushNotification = pushNotification;
|
||||
|
||||
SetStyles();
|
||||
|
||||
@@ -64,6 +68,11 @@ namespace Bit.App
|
||||
{
|
||||
await CheckLockAsync(args);
|
||||
});
|
||||
|
||||
MessagingCenter.Subscribe<Application, string>(Current, "Logout", (sender, args) =>
|
||||
{
|
||||
Logout(args);
|
||||
});
|
||||
}
|
||||
|
||||
protected async override void OnStart()
|
||||
@@ -166,6 +175,20 @@ namespace Bit.App
|
||||
}
|
||||
}
|
||||
|
||||
private void Logout(string logoutMessage)
|
||||
{
|
||||
_authService.LogOut();
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
_pushNotification.Unregister();
|
||||
});
|
||||
Current.MainPage = new HomePage();
|
||||
if(!string.IsNullOrWhiteSpace(logoutMessage))
|
||||
{
|
||||
_userDialogs.WarnToast("Logged out", logoutMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CheckLockAsync(bool forceLock)
|
||||
{
|
||||
// Only lock if they are logged in
|
||||
|
||||
Reference in New Issue
Block a user