fix cli incorrect license error and warning

resolves https://github.com/abpframework/abp/issues/2626
pull/2635/head
Yunus Emre Kalkan 5 years ago
parent 530f5c6b23
commit 524ed4328d

@ -45,5 +45,10 @@ namespace Volo.Abp.Cli.Auth
FileHelper.DeleteIfExists(CliPaths.AccessToken);
return Task.CompletedTask;
}
public static bool IsLoggedIn()
{
return File.Exists(CliPaths.AccessToken);
}
}
}

@ -3,6 +3,7 @@ using System.IO;
using System.Net.Http;
using System.Text;
using IdentityModel.Client;
using Volo.Abp.Cli.Auth;
namespace Volo.Abp.Cli.Http
{
@ -29,7 +30,7 @@ namespace Volo.Abp.Cli.Http
private static void AddAuthentication(HttpClient client)
{
if (!File.Exists(CliPaths.AccessToken))
if (!AuthService.IsLoggedIn())
{
return;
}

@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Polly;
using Polly.Extensions.Http;
using Volo.Abp.Cli.Auth;
using Volo.Abp.Cli.Http;
using Volo.Abp.Cli.ProjectBuilding;
using Volo.Abp.DependencyInjection;
@ -31,6 +32,11 @@ namespace Volo.Abp.Cli.Licensing
public async Task<DeveloperApiKeyResult> GetApiKeyOrNullAsync(bool invalidateCache = false)
{
if (!AuthService.IsLoggedIn())
{
return null;
}
if (invalidateCache)
{
_apiKeyResult = null;
@ -81,16 +87,6 @@ namespace Volo.Abp.Cli.Licensing
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var apiKeyResult = JsonSerializer.Deserialize<DeveloperApiKeyResult>(responseContent);
if (string.IsNullOrEmpty(apiKeyResult?.ApiKey))
{
_logger.LogError("Couldn't retrieve your NuGet API key!");
_logger.LogWarning(File.Exists(CliPaths.AccessToken)
? "Make sure you have an active session and license on commercial.abp.io. To re-sign in you can use the CLI command \"abp login <username>\"."
: "You are not signed in to commercial.abp.io. Use the CLI command \"abp login <username>\" to sign in.");
return null;
}
return apiKeyResult;
}
}

Loading…
Cancel
Save