mod: impl config for api url
All checks were successful
Release Mod / Build (push) Successful in 25s
All checks were successful
Release Mod / Build (push) Successful in 25s
This commit is contained in:
@ -9,36 +9,7 @@ namespace ScoreTracker.API
|
||||
{
|
||||
internal class Request
|
||||
{
|
||||
private static readonly HttpClient client = new HttpClient();
|
||||
|
||||
private class AuthHelper
|
||||
{
|
||||
public bool IsLoggedIn;
|
||||
public string FailReason = "";
|
||||
|
||||
public async Task EnsureLoggedIn()
|
||||
{
|
||||
if (Authentication.IsSignedIn() && await Authentication.ValidateAuthToken())
|
||||
{
|
||||
return; // Already logged in with a valid token
|
||||
}
|
||||
|
||||
await Authentication.LoginUser(
|
||||
token => {
|
||||
IsLoggedIn = true;
|
||||
PersistHeaders(new Dictionary<string, string>
|
||||
{
|
||||
{ "Authorization", $"Bearer {token}" }
|
||||
});
|
||||
},
|
||||
reason =>
|
||||
{
|
||||
FailReason = reason; // Store the reason for failure
|
||||
client.DefaultRequestHeaders.Clear(); // Clear headers
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
internal static readonly HttpClient HttpClient = new HttpClient();
|
||||
|
||||
/// <summary>
|
||||
/// Persist the given headers for all future requests
|
||||
@ -46,10 +17,10 @@ namespace ScoreTracker.API
|
||||
/// <param name="headers">the headers to persist</param>
|
||||
public static void PersistHeaders(Dictionary<string, string> headers)
|
||||
{
|
||||
client.DefaultRequestHeaders.Clear(); // Clear existing headers
|
||||
HttpClient.DefaultRequestHeaders.Clear(); // Clear existing headers
|
||||
foreach (var header in headers)
|
||||
{
|
||||
client.DefaultRequestHeaders.Add(header.Key, header.Value);
|
||||
HttpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +46,7 @@ namespace ScoreTracker.API
|
||||
var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
|
||||
|
||||
// Send the POST request
|
||||
var response = await client.PostAsync(url, content);
|
||||
var response = await HttpClient.PostAsync(url, content);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user