Update how we handle invalid tokens

This commit is contained in:
Timothy Baldridge 2021-12-18 09:29:56 -07:00
parent 19ad2ec331
commit 270362db56

View File

@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using SharpCompress.Crypto;
using Wabbajack.DTOs.Logins;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Networking.Http.Interfaces;
@ -18,9 +19,21 @@ public class WabbajackApiTokenProvider : ITokenProvider<WabbajackApiState>
if (!MetricsPath.FileExists())
await CreateMetricsKey();
string wjToken;
try
{
wjToken = (await MetricsPath.FromEncryptedJsonFile<string>())!;
}
catch (CryptoException)
{
MetricsPath.Delete();
await CreateMetricsKey();
wjToken = (await MetricsPath.FromEncryptedJsonFile<string>())!;
}
return new WabbajackApiState
{
MetricsKey = (await MetricsPath.FromEncryptedJsonFile<string>())!,
MetricsKey = wjToken,
AuthorKey = AuthorKeyPath.FileExists() ? await AuthorKeyPath.ReadAllTextAsync() : null
};
}