AuthenticationWithClientSideBlazor
AuthenticationWithClientSideBlazor copied to clipboard
Code Works. Change this: AuthService -> Register
I'm not sure if this is a .Net 3.1 vs 5 issue. However, the Post call in the current code uses PostJsonAsync. I believe the correct call is PostAsJsonAsync.
Also even with using PostAsJsonAsync, the compiler throws an error because the return is an HttpResponseMessage and not a RegisterResult. As a whole, I believe the correct code is as follows:
public async Task<RegisterResult> Register(RegisterModel registerModel)
{
var result = await _httpClient.PostAsJsonAsync<RegisterModel>("api/accounts", registerModel);
var registerResult = result.Content.ReadFromJsonAsync<RegisterResult>().Result;
return registerResult;
}
With this modification, the code works great. Thanks for a wonderful example!! I'm looking forward to your book.