Skip to content

Commit

Permalink
fix: improve refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
iadonkey authored Mar 27, 2024
1 parent f28c74f commit a690e87
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions TwinpackShared/TwinpackServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class TwinpackServer

private CachedHttpClient _client = new CachedHttpClient();
private Timer _refreshTokenTimer;
private string _token = string.Empty;

public string TwinpackUrlBase = "https://twinpack.dev";
public string TwinpackUrl = "https://twinpack.dev/index.php";
Expand Down Expand Up @@ -580,6 +579,11 @@ public async Task<LoginPostResponse> LoginAsync(string username = null, string p

Username = username ?? credentials?.UserName;
Password = password ?? credentials?.Password;

// reset token to get a new one
if(UserInfo?.Token != null)
UserInfo.Token = null;

AddHeaders(request);
var response = await _client.SendAsync(request, cancellationToken);
var responseBody = await response.Content.ReadAsStringAsync();
Expand Down Expand Up @@ -633,10 +637,6 @@ private async Task RefreshTokenAsync()

if(UserInfo?.Token != null)
{
// make sure the server doesn't kick us if our timezone is completely off for some reason
if (delay.Minutes < 0)
delay = new TimeSpan(0, 1, 0);

await Task.Delay(delay, CancellationToken.None);
await LoginAsync();
}
Expand Down

0 comments on commit a690e87

Please sign in to comment.