fucodo/conditional-redirect

Maintainers

Package info

github.com/fucodo/fucodo.conditional.redirect

Type:neos-package

pkg:composer/fucodo/conditional-redirect

Transparency log

Statistics

Installs: 22

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-08-06 09:20 UTC

This package is auto-updated.

Last update: 2026-08-06 09:21:16 UTC


README

This Neos Flow package provides a PSR-15 middleware to conditionally redirect requests based on Eel expressions. It is designed to intercept requests after routing and security entry points, but before dispatching to a controller.

Features

  • Eel-based conditions: Use powerful Eel expressions to decide when a redirect should happen.
  • Role-based checks: Includes a securityContext Eel helper for role membership and authentication checks.
  • Global Whitelist: Prevent redirection for specific routes (e.g., login, logout, authentication) using a configurable whitelist.
  • Redirect Loop Protection: Limits the number of consecutive redirects to prevent infinite loops, with configurable maximum redirects.
  • Original Request Storage: Automatically stores the original request URI in the session, allowing targets to redirect the user back after handling the condition (e.g., after successful onboarding).
  • Custom Status Codes: Support for different HTTP redirect status codes (default is 303).

Installation

Add the package via composer:

{
    "require": {
        "fucodo/conditional-redirect": "*"
    }
}

Configuration

The package is configured via Settings.yaml.

Example Configuration

fucodo:
  conditional:
    redirect:
      enabled: true
      
      # Rules are checked in order. The first matching rule wins.
      rules:
        onboardingRedirect:
          condition: "${securityContext.isAuthenticated() && !securityContext.hasRole('Some.Package:AlreadyOnboarded')}"
          target:
            package: 'Some.Package'
            controller: 'Onboarding'
            action: 'index'
            arguments: {}
            statusCode: 303

      # Whitelist targets that should NEVER be redirected
      whitelist:
        login:
          enabled: true
          package: 'Neos.Neos'
          controller: 'Login'
          action: 'index'
        logout:
          enabled: true
          package: 'Neos.Neos'
          controller: 'Login'
          action: 'logout'

      # Redirect loop protection
      redirectLoop:
        maxRedirects: 5
        counterSessionKey: 'fucodo_conditional_redirect_Counter'
        originalRequestSessionKey: 'fucodo_conditional_redirect_OriginalRequest'

      # Whether to store the original request URI in the session
      storeOriginalRequest: true

Eel Context

The following variables are available in the Eel expressions:

  • request: The current ServerRequestInterface.
  • actionRequest: The resolved ActionRequest.
  • controllerObjectName: The name of the target controller class.
  • controllerName: The short name of the target controller.
  • actionName: The name of the target action.
  • packageKey: The package key of the target.
  • arguments: The arguments for the action.
  • account: The currently authenticated account (if any).
  • securityContext: An instance of fucodo\conditional\redirect\Eel\SecurityHelper.

SecurityHelper Methods

  • securityContext.hasRole(roleIdentifier): Returns true if the current account has the specified role.
  • securityContext.isAuthenticated(): Returns true if an account is authenticated.
  • securityContext.getAccountIdentifier(): Returns the identifier of the current account or null.

Middleware Position

The middleware is automatically registered in Settings.Neos.Flow.http.yaml and positioned after securityEntryPoint to ensure authentication data is available for the Eel expressions.