Skip to content

Commit c46702f

Browse files
committed
Subject: Update name variable assignment in CascadeAuthState.razor
Body: Updated the assignment of the `name` variable in `CascadeAuthState.razor` to prevent potential `NullReferenceException`. The new code uses the null-conditional operator to check if the user has a claim of type "name". If not, it assigns an empty string to `name` using the null-coalescing operator, ensuring `name` is always assigned a string value.
1 parent 92292c6 commit c46702f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

WebApp/Components/Pages/User/CascadeAuthState.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
if (user?.Identity is not null && user.Identity.IsAuthenticated)
2222
{
23-
var name = user.FindFirst("name").Value;
23+
string name = user.FindFirst("name")?.Value ?? string.Empty;
2424
if (user.IsInRole("Admin"))
2525
{
2626
authMessage = $"{name} is authenticated and in the Admin role.";

0 commit comments

Comments
 (0)