Skip to content

Commit

Permalink
Improve logic for token check
Browse files Browse the repository at this point in the history
The base GiHub command class performs authentication with whatever token is already set. This means we might succeed with the older token, not the new one provided.
  • Loading branch information
kzu committed Oct 1, 2024
1 parent b9b9830 commit 99a6554
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Commands/CheckTokenCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ public class CheckSettings : ToSSettings

public override async Task<int> ExecuteAsync(CommandContext context, CheckSettings settings)
{
if (await base.ExecuteAsync(context, settings) is not 0)
return -1;

using var withToken = GitHub.WithToken(settings.Token);

if (withToken is null)
// NOTE: gh cli will not set an invalid token, so we first need to check for that (null withToken)
// before checking the base execute which will also authenticate.
if (withToken is null || await base.ExecuteAsync(context, settings) is not 0)
{
AnsiConsole.MarkupLine("[red]Invalid token[/]");
AnsiConsole.MarkupLine(":cross_mark: [yellow]Invalid GitHub token provided[/]");
return -1;
}

Expand Down

0 comments on commit 99a6554

Please sign in to comment.