configure-auth

Configure authentication and authorization in Blazor Web Apps across render modes.

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/D1ssolve/craft-agents --skill configure-auth-d1ssolve
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: configure-auth
Source: https://github.com/D1ssolve/craft-agents/tree/main/skills/configure-auth
Command: npx skills add https://github.com/D1ssolve/craft-agents --skill configure-auth-d1ssolve

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Adding authentication to a Blazor Web App is error-prone because behavior differs across static SSR, interactive Server, and WebAssembly render modes, causing null auth state, SignInManager exceptions, and broken Identity pages. ## Core Features & Use Cases - Render-mode-aware setup: Registers cascading authentication state, Identity services, and wires App.razor with AuthorizeRouteView and AcceptsInteractiveRouting. - Page and component protection: Applies [Authorize] attributes, role and policy checks, AuthorizeView conditional UI, and cascading AuthenticationState access. - WebAssembly auth serialization: Configures AddAuthenticationStateSerialization and Deserialization so auth state survives the prerender-to-WASM transition. - Use Case: A developer adds login to a globally interactive Blazor app and finds Identity pages crash; this Skill marks them with [ExcludeFromInteractiveRouting] so they render as static SSR with a real HttpContext. ## Quick Start Add authentication with ASP.NET Core Identity to my Blazor Web App and protect the admin pages with role-based authorization.

Frequently Asked Questions about configure-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add authentication to a Blazor Web App?

Register AddCascadingAuthenticationState and AddAuthorization in Program.cs, add Identity services with AddIdentityCore and AddIdentityCookies, then use AuthorizeRouteView in your router. Protect pages with the [Authorize] attribute and use AuthorizeView for conditional UI.

How to use role-based authorization in Blazor pages?

Apply [Authorize(Roles = "Admin")] or [Authorize(Policy = "RequireManager")] attributes on routable pages. For conditional UI, use AuthorizeView with the Roles parameter, and check state.User.IsInRole in code via the cascading AuthenticationState.

Why is AuthenticationState null after WebAssembly loads in Blazor?

WebAssembly components have no HttpContext, so auth state must be serialized during prerendering. Add AddAuthenticationStateSerialization in the server Program.cs and AddAuthenticationStateDeserialization in the client Program.cs to fix anonymous user state.

Why does SignInManager throw in an interactive Blazor component?

SignInManager and UserManager depend on HttpContext, which is unavailable in interactive components. Move login and registration logic to static SSR pages marked with [ExcludeFromInteractiveRouting] in globally interactive apps.

Why does NotAuthorized content never render in static SSR?

Static SSR uses the middleware pipeline rather than the interactive router, so NotAuthorized fragments do not render. Redirect unauthenticated users via LoginPath configuration or a RedirectToLogin component instead.