In blazor template httpclient is added in the Program.cs class:
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
and later used as following:
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
is there any way that I can override that base httpclient and inject it to all of my pages, that would:
- catch a 401 returned in any sever request (post/get etc.)
- try refreshing the token (call API for that)
- return to login when it fails to refresh
I saw that I could define a custom service that would wrap all of those HTTP client calls and perform the actions that I mention, however is there a way to do it in a better way?