Users were experiencing an infinite redirect loop after logging in:
- Login succeeds (HTTP 200)
- Redirect to
/admin/dashboard - GDPR Cookie Consent Wall appears
- User is redirected back to
/login?returnUrl=... - Loop continues indefinitely
The issue was caused by the interaction between:
- CookieConsentWall component: Blocking page interaction immediately on load
- Authorization attribute:
[Authorize(Roles = "Admin")]on Dashboard page - Authentication state: Temporary disruption during wall initialization
- RedirectToLogin component: Automatically triggered when auth check fails
The cookie consent wall's JavaScript blockInteraction() function was interfering with Blazor's authentication state management, causing the auth check to fail momentarily and trigger an unwanted redirect.
@if (!IsAuthPage())
{
<CookieConsentWall />
}- Added
IsAuthPage()method to detect login/register pages - Cookie wall is NOT rendered on authentication pages
// Check authentication state before showing wall
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var isAuthenticated = authState.User?.Identity?.IsAuthenticated ?? false;
// Delay showing the wall if user just authenticated
if (isAuthenticated)
{
await Task.Delay(1000); // Give navigation time to complete
}- Added delays to prevent interference with navigation
- Check auth state before blocking interaction
Navigation.LocationChanged += OnLocationChanged;
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
// Hide wall when navigating to auth pages
var currentPath = Navigation.ToBaseRelativePath(e.Location).ToLower();
if (currentPath.StartsWith("login") || currentPath.StartsWith("register"))
{
showWall = false;
}
}- Subscribe to navigation events
- Automatically hide wall on auth page navigation
blockInteraction: function() {
// Only block if not on an auth page
const currentPath = window.location.pathname.toLowerCase();
if (currentPath.includes('/login') ||
currentPath.includes('/register')) {
console.log('[COOKIE-WALL-JS] On auth page - not blocking');
return;
}
document.body.style.overflow = 'hidden';
}- Added path checking in JavaScript
- Prevents blocking on auth pages
-
/src/InsightLearn.WebAssembly/Layout/MainLayout.razor- Added
IsAuthPage()method - Conditional rendering of CookieConsentWall
- Added
-
/src/InsightLearn.WebAssembly/Components/CookieConsentWall.razor- Added AuthenticationStateProvider injection
- Implemented IDisposable for cleanup
- Added navigation event handling
- Added delays to prevent interference
- Path checking before showing wall
-
/src/InsightLearn.WebAssembly/wwwroot/js/cookie-consent-wall.js- Added path checking in blockInteraction()
- Improved pointer-events handling
- User visits site → NO wall on login page
- User logs in → Redirected to dashboard
- After navigation completes → GDPR wall appears
- User accepts cookies → Wall hidden, localStorage saved
- Dashboard fully accessible
- User with saved consent logs in
- Redirected to dashboard
- NO wall appears (consent already saved)
- Dashboard immediately accessible
- User visits public page → GDPR wall appears
- User accepts cookies → Wall hidden
- User navigates to login → NO wall
- User logs in → Dashboard accessible
- Clear browser localStorage (remove 'cookie-consent' key)
- Navigate to
/login - Verify NO cookie wall appears
- Login with valid credentials
- Verify redirect to dashboard
- Verify cookie wall appears AFTER navigation
- Accept cookies
- Verify dashboard is accessible
- Logout and login again
- Verify NO wall appears (consent saved)
Run the test script:
./test-cookie-consent-fix.shLook for these console messages:
[COOKIE-WALL] On auth page - not showing wall[COOKIE-WALL] User is authenticated - delaying wall display[COOKIE-WALL-JS] On auth page - not blocking interaction
- Never show wall on auth pages - Login/register must be accessible
- Delay blocking interactions - Allow navigation to complete
- Check authentication state - Don't interfere with auth flow
- Path-aware blocking - JavaScript double-checks current page
- Clean up event handlers - Prevent memory leaks with IDisposable
If redirect loop persists:
- Check browser console for errors
- Clear all browser data (cache, cookies, localStorage)
- Verify all files were updated correctly
- Check network tab for redirect chain
- Ensure JWT tokens are valid
Consider these enhancements:
- Server-side cookie consent tracking
- Gradual consent (ask for analytics/marketing later)
- Cookie consent management page
- A/B testing different consent UI designs
- Integration with consent management platforms
/src/InsightLearn.WebAssembly/App.razor- Main routing configuration/src/InsightLearn.WebAssembly/Components/RedirectToLogin.razor- Redirect component/src/InsightLearn.WebAssembly/Pages/Admin/Dashboard.razor- Protected page/src/InsightLearn.WebAssembly/wwwroot/css/cookie-consent-wall.css- Styling