Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second edition #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
20 changes: 11 additions & 9 deletions Auth0BlazorServer/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@page "/"
@inject AuthenticationStateProvider AuthState
@attribute [Authorize]

<PageTitle>Auth0 Blazor Server</PageTitle>
Expand All @@ -12,18 +11,21 @@ You can only see this content if you're authenticated.
@code {
private string Username = "Anonymous User";
private string Picture = "";

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }
protected override async Task OnInitializedAsync()
{
var state = await AuthState.GetAuthenticationStateAsync();

Username = state.User.Identity.Name?? string.Empty;
if (authenticationState is not null)
{
var state = await authenticationState;

Picture = state.User.Claims
.Where(c => c.Type.Equals("picture"))
.Select(c => c.Value)
.FirstOrDefault() ?? string.Empty;
Username = state?.User?.Identity?.Name?? string.Empty;

Picture = state?.User.Claims
.Where(c => c.Type.Equals("picture"))
.Select(c => c.Value)
.FirstOrDefault() ?? string.Empty;
}
await base.OnInitializedAsync();
}
}
Loading