Since a sync operation is running on a background thread and is long-running, it is possible someone could log out during its processing. Do some auth checking during the loops process.

This commit is contained in:
Kyle Spearrin 2016-08-06 01:48:24 -04:00
parent 48b5545a33
commit 33a01c0512

View file

@ -224,10 +224,19 @@ namespace Bit.App.Services
private async Task SyncFoldersAsync(IEnumerable<CipherResponse> serverFolders, bool deleteMissing) private async Task SyncFoldersAsync(IEnumerable<CipherResponse> serverFolders, bool deleteMissing)
{ {
if(!_authService.IsAuthenticated)
{
return;
}
var localFolders = await _folderRepository.GetAllByUserIdAsync(_authService.UserId); var localFolders = await _folderRepository.GetAllByUserIdAsync(_authService.UserId);
foreach(var serverFolder in serverFolders) foreach(var serverFolder in serverFolders)
{ {
if(!_authService.IsAuthenticated)
{
return;
}
var existingLocalFolder = localFolders.SingleOrDefault(f => f.Id == serverFolder.Id); var existingLocalFolder = localFolders.SingleOrDefault(f => f.Id == serverFolder.Id);
if(existingLocalFolder == null) if(existingLocalFolder == null)
{ {
@ -254,10 +263,20 @@ namespace Bit.App.Services
private async Task SyncSitesAsync(IEnumerable<CipherResponse> serverSites, bool deleteMissing) private async Task SyncSitesAsync(IEnumerable<CipherResponse> serverSites, bool deleteMissing)
{ {
if(!_authService.IsAuthenticated)
{
return;
}
var localSites = await _siteRepository.GetAllByUserIdAsync(_authService.UserId); var localSites = await _siteRepository.GetAllByUserIdAsync(_authService.UserId);
foreach(var serverSite in serverSites) foreach(var serverSite in serverSites)
{ {
if(!_authService.IsAuthenticated)
{
return;
}
var existingLocalSite = localSites.SingleOrDefault(s => s.Id == serverSite.Id); var existingLocalSite = localSites.SingleOrDefault(s => s.Id == serverSite.Id);
if(existingLocalSite == null) if(existingLocalSite == null)
{ {
@ -287,6 +306,11 @@ namespace Bit.App.Services
var tasks = new List<Task>(); var tasks = new List<Task>();
foreach(var cipherId in cipherIds) foreach(var cipherId in cipherIds)
{ {
if(!_authService.IsAuthenticated)
{
return;
}
tasks.Add(_siteRepository.DeleteAsync(cipherId)); tasks.Add(_siteRepository.DeleteAsync(cipherId));
tasks.Add(_folderRepository.DeleteAsync(cipherId)); tasks.Add(_folderRepository.DeleteAsync(cipherId));
} }