Class AuthStatusUpdateFilter
- Namespace
- Htmx.Components.AuthStatus.Internal
- Assembly
- Htmx.Components.dll
A result filter that automatically updates authentication status and navigation components when controller actions are marked with the AuthStatusUpdateAttribute. This filter performs out-of-band updates for both the navigation bar and authentication status displays.
public class AuthStatusUpdateFilter : OobResultFilterBase<AuthStatusUpdateAttribute>, IAsyncResultFilter, IFilterMetadata
- Inheritance
-
AuthStatusUpdateFilter
- Implements
- Inherited Members
- Extension Methods
Remarks
This filter is designed specifically for HTMX requests and will throw an exception if used with non-HTMX requests. For non-HTMX scenarios, use the AuthStatusViewComponent directly. The filter automatically refreshes the navigation and authentication status to reflect any changes that may have occurred during the request processing.
Example Pattern for Custom Component Filters:
This filter demonstrates the standard pattern for creating component-specific filters that coordinate multiple out-of-band updates. When creating custom components that need coordinated updates in response to specific events, follow this same pattern:
- Create a custom filter that inherits from OobResultFilterBase<T> with your custom attribute
- Keep the filter focused on a single responsibility (e.g., auth-related updates, data-related updates)
- Override UpdateMultiSwapViewResultAsync(AuthStatusUpdateAttribute, MultiSwapViewResult, ResultExecutingContext) to include only the related component updates
- Register your filter in the MVC pipeline alongside existing filters
Example: A separate filter for user profile-related components would be implemented as its own filter class rather than modifying this authentication-focused filter, maintaining single responsibility.
Constructors
AuthStatusUpdateFilter(INavProvider, IAuthStatusProvider, ViewPaths)
Initializes a new instance of the AuthStatusUpdateFilter class.
public AuthStatusUpdateFilter(INavProvider navProvider, IAuthStatusProvider authStatusProvider, ViewPaths viewPaths)
Parameters
navProvider
INavProviderThe navigation provider for building updated navigation content.
authStatusProvider
IAuthStatusProviderThe authentication status provider for building updated authentication status content.
viewPaths
ViewPathsThe view paths configuration for component views.
Methods
GetViewNameForNonHtmxRequest(AuthStatusUpdateAttribute, ControllerActionDescriptor)
Throws a NotSupportedException as this filter is designed only for HTMX requests. For non-HTMX scenarios, use the AuthStatusViewComponent directly in your views.
protected override Task<string?> GetViewNameForNonHtmxRequest(AuthStatusUpdateAttribute attribute, ControllerActionDescriptor cad)
Parameters
attribute
AuthStatusUpdateAttributeThe AuthStatusUpdateAttribute instance.
cad
ControllerActionDescriptorThe controller action descriptor.
Returns
Exceptions
- NotSupportedException
Always thrown as this filter doesn't support non-HTMX requests.
UpdateMultiSwapViewResultAsync(AuthStatusUpdateAttribute, MultiSwapViewResult, ResultExecutingContext)
Updates the MultiSwapViewResult with refreshed navigation bar and authentication status content. This method performs out-of-band updates for both components to ensure they reflect the current state.
protected override Task UpdateMultiSwapViewResultAsync(AuthStatusUpdateAttribute attribute, MultiSwapViewResult multiSwapViewResult, ResultExecutingContext context)
Parameters
attribute
AuthStatusUpdateAttributeThe AuthStatusUpdateAttribute that triggered this filter.
multiSwapViewResult
MultiSwapViewResultThe MultiSwapViewResult to update with out-of-band content.
context
ResultExecutingContextThe result executing context containing request and user information.
Returns
- Task
A task representing the asynchronous update operation.
Remarks
Implementation Example for Component Developers:
This method demonstrates the standard pattern for implementing coordinated component updates in a filter. The pattern shown here should be followed when creating similar filters for other component groups, maintaining single responsibility within each filter.
The implementation pattern demonstrated:
1. Retrieve updated data from appropriate providers (e.g., INavProvider, IAuthStatusProvider)
2. Use multiSwapViewResult.WithOobContent()
to add each related component update
3. Target components using their well-known names from ComponentNames
4. Keep updates focused on the filter's single responsibility (authentication-related components)