Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Adds authentication and authorization to Blazor Web Apps, covering Identity setup, render mode handling and access control.
59% 100%+41 ptsof test cases passed
Passed 22 of 22 test cases with the skill, and 13 of 22 without it.
We want to display 'Welcome Admin' when an admin user views a component, and a login hyperlink for everyone else. What component wrapper should we use?
Uses AuthorizeView component with Authorized and NotAuthorized templates
3 of 3 safety checks passed
Read AGENTS.md at the workspace root for the project's interactivity mode and scope before making changes.
// Program.cs (server project)
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddAuthorization();
For ASP.NET Core Identity add the Identity services:
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = IdentityConstants.ApplicationScheme;
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})
.AddIdentityCookies();
builder.Services.AddIdentityCore<ApplicationUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddSignInManager()
.AddDefaultTokenProviders();
The App.razor component must use AuthorizeRouteView and conditionally apply the render mode so that pages excluded from interactive routing render statically.
<!DOCTYPE html>
<html>
<head>
<HeadOutlet @rendermode="RenderModeForPage" />
Next to this one in the catalogue, plus more from the same author.