Skip to content

Commit 28d960a

Browse files
authored
Add logger and move RoleClaim class (#402)
1 parent 0aab0d4 commit 28d960a

File tree

4 files changed

+50
-26
lines changed

4 files changed

+50
-26
lines changed

8.0/BlazorWebAssemblyStandaloneWithIdentity/BlazorWasmAuth/Identity/CookieAuthenticationStateProvider.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace BlazorWasmAuth.Identity
1414
/// Create a new instance of the auth provider.
1515
/// </remarks>
1616
/// <param name="httpClientFactory">Factory to retrieve auth client.</param>
17-
public class CookieAuthenticationStateProvider(IHttpClientFactory httpClientFactory) : AuthenticationStateProvider, IAccountManagement
17+
public class CookieAuthenticationStateProvider(IHttpClientFactory httpClientFactory, ILogger<CookieAuthenticationStateProvider> logger)
18+
: AuthenticationStateProvider, IAccountManagement
1819
{
1920
/// <summary>
2021
/// Map the JavaScript-formatted properties to C#-formatted classes.
@@ -95,7 +96,10 @@ public async Task<FormResult> RegisterAsync(string email, string password)
9596
ErrorList = problemDetails == null ? defaultDetail : [.. errors]
9697
};
9798
}
98-
catch { }
99+
catch (Exception ex)
100+
{
101+
logger.LogError(ex, "App error");
102+
}
99103

100104
// unknown error
101105
return new FormResult
@@ -133,7 +137,10 @@ public async Task<FormResult> LoginAsync(string email, string password)
133137
return new FormResult { Succeeded = true };
134138
}
135139
}
136-
catch { }
140+
catch (Exception ex)
141+
{
142+
logger.LogError(ex, "App error");
143+
}
137144

138145
// unknown error
139146
return new FormResult
@@ -214,7 +221,10 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
214221
authenticated = true;
215222
}
216223
}
217-
catch { }
224+
catch (Exception ex)
225+
{
226+
logger.LogError(ex, "App error");
227+
}
218228

219229
// return the state
220230
return new AuthenticationState(user);
@@ -233,14 +243,5 @@ public async Task<bool> CheckAuthenticatedAsync()
233243
await GetAuthenticationStateAsync();
234244
return authenticated;
235245
}
236-
237-
public class RoleClaim
238-
{
239-
public string? Issuer { get; set; }
240-
public string? OriginalIssuer { get; set; }
241-
public string? Type { get; set; }
242-
public string? Value { get; set; }
243-
public string? ValueType { get; set; }
244-
}
245246
}
246247
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace BlazorWasmAuth.Identity.Models
2+
{
3+
public class RoleClaim
4+
{
5+
public string? Issuer { get; set; }
6+
public string? OriginalIssuer { get; set; }
7+
public string? Type { get; set; }
8+
public string? Value { get; set; }
9+
public string? ValueType { get; set; }
10+
}
11+
}

9.0/BlazorWebAssemblyStandaloneWithIdentity/BlazorWasmAuth/Identity/CookieAuthenticationStateProvider.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace BlazorWasmAuth.Identity
1414
/// Create a new instance of the auth provider.
1515
/// </remarks>
1616
/// <param name="httpClientFactory">Factory to retrieve auth client.</param>
17-
public class CookieAuthenticationStateProvider(IHttpClientFactory httpClientFactory) : AuthenticationStateProvider, IAccountManagement
17+
public class CookieAuthenticationStateProvider(IHttpClientFactory httpClientFactory, ILogger<CookieAuthenticationStateProvider> logger)
18+
: AuthenticationStateProvider, IAccountManagement
1819
{
1920
/// <summary>
2021
/// Map the JavaScript-formatted properties to C#-formatted classes.
@@ -95,7 +96,10 @@ public async Task<FormResult> RegisterAsync(string email, string password)
9596
ErrorList = problemDetails == null ? defaultDetail : [.. errors]
9697
};
9798
}
98-
catch { }
99+
catch (Exception ex)
100+
{
101+
logger.LogError(ex, "App error");
102+
}
99103

100104
// unknown error
101105
return new FormResult
@@ -133,7 +137,10 @@ public async Task<FormResult> LoginAsync(string email, string password)
133137
return new FormResult { Succeeded = true };
134138
}
135139
}
136-
catch { }
140+
catch (Exception ex)
141+
{
142+
logger.LogError(ex, "App error");
143+
}
137144

138145
// unknown error
139146
return new FormResult
@@ -214,7 +221,10 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
214221
authenticated = true;
215222
}
216223
}
217-
catch { }
224+
catch (Exception ex)
225+
{
226+
logger.LogError(ex, "App error");
227+
}
218228

219229
// return the state
220230
return new AuthenticationState(user);
@@ -233,14 +243,5 @@ public async Task<bool> CheckAuthenticatedAsync()
233243
await GetAuthenticationStateAsync();
234244
return authenticated;
235245
}
236-
237-
public class RoleClaim
238-
{
239-
public string? Issuer { get; set; }
240-
public string? OriginalIssuer { get; set; }
241-
public string? Type { get; set; }
242-
public string? Value { get; set; }
243-
public string? ValueType { get; set; }
244-
}
245246
}
246247
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace BlazorWasmAuth.Identity.Models
2+
{
3+
public class RoleClaim
4+
{
5+
public string? Issuer { get; set; }
6+
public string? OriginalIssuer { get; set; }
7+
public string? Type { get; set; }
8+
public string? Value { get; set; }
9+
public string? ValueType { get; set; }
10+
}
11+
}

0 commit comments

Comments
 (0)