TYPO3 Frontend Login

Extension key

felogin

Package name

typo3/cms-felogin

Version

13.4

Language

en

Author

TYPO3 contributors

License

This document is published under the Open Content License.

Rendered

Tue, 08 Jul 2025 09:27:25 +0000


This extension provides a template-based plugin that allows website users to log in to the TYPO3 frontend.


Table of Contents:

Introduction

What does it do?

The Frontend Login for Website Users (felogin) extension is a general purpose extension for frontend logins. In addition to the actual login box, it includes several methods for redirecting after login/logout and includes forgot password functionality.

Screenshots

General Settings

General Settings

The plugin's general settings

Redirect Configuration

Redirect Configuration

Configuration of the redirection options

Messages Tab

Messages Configuration

Configuration of the various messages (screenshot shows not all options)

Installation

This extension is part of the TYPO3 Core, but not installed by default.

Table of contents

Installation with Composer

Check whether you are already using the extension with:

composer show | grep felogin
Copied!

This should either give you no result or something similar to:

typo3/cms-felogin       v12.4.11
Copied!

If it is not installed yet, use the composer require command to install the extension:

composer require typo3/cms-felogin
Copied!

The given version depends on the version of the TYPO3 Core you are using.

Installation without Composer

In an installation without Composer, the extension is already shipped but might not be activated yet. Activate it as follows:

  1. In the backend, navigate to the Admin Tools > Extensions module.
  2. Click the Activate icon for the Frontend Login extension.
Extension manager showing Frontend Login extension

Extension manager showing Frontend Login extension

Next steps

Configure the Frontend Login.

Users manual

The felogin extension requires no special configuration. All options are available in the plugin's FlexForm as shown in the Screenshots.

Using the plugin

The felogin plugin is available through the Content Wizard as Login Form:

The content element wizard

The Login Form plugin in the content element wizard

Choosing a user storage page for website users

In order for Website Users to be able to log in, the "Frontend login" plugin must know where the records are stored. There are two possibilities for setting this storage folder:

The site's integrator may have set a default value for the User Storage Page or using the Settings editor. If you use the default folder to store frontend users in your project there is nothing to do here.

If your project needs multiple storage folders for frontend users or if there is no default storage folder set, see Example: Override the default storage page in the plugin's FlexForm.

Access restrictions on the felogin plugin

A very common issue is, that the felogin plugin is set to Access: Hide at login. After the core has processed the login request, the page will be rendered without the felogin plugin. If there are redirect options active they will not be executed, simply because the felogin plugin is hidden.

Of course setting the felogin plugin to Hide at login and having redirect options together doesn't really makes sense.

Login mechanism

In order to properly use the felogin plugin and its advanced capabilities (such as redirect options) it is important to understand the mechanism of frontend user login in TYPO3 CMS.

What is displayed?

If there is no frontend user logged in, the login form will be shown.

If there is a logged in frontend user, the logout form is shown.

If the forgot password link was used, the form to reset a password based on username or email address will be shown.

If the password reset link was followed from an email, the form to change the password will be shown.

The login process

After the form is submitted the TYPO3 CMS authentication services will validate the login credentials. After this process felogin will handle the rest. This means that the felogin plugin must be visible for the user who has logged in.

Felogin will then check any redirect options and generate the appropriate content.

Redirect Modes

The following redirect options are supported.

Defined by Usergroup Record

Within a Website usergroup record, you can specify a page where usergroup members will be redirected after login.

Defined by User Record

This is identical to the redirection option for "defined by Usergroup Record" but applies to a single website user instead of an entire user group.

After Login (TS or Flexform)

This redirect page is set either in TypoScript ( plugin.tx_felogin_login.settings.redirectPageLogin) or in the FlexForm of the felogin plugin.

After Logout (TS or Flexform)

Defines the redirect page after a user has logged out. Again, it can be set in TypoScript or in the felogin plugin's FlexForm.

After Login Error (TS of Flexform)

Defines the redirect page after a login error occurs. Can be set in TypoScript or in the felogin plugin's FlexForm.

Defined by GET/POST Parameters

Redirect the visitor based on the GET/POST parameters redirect_url. If the TypoScript configuration config.typolinkLinkAccessRestrictedPages is set, the GET/POST parameter redirect_url is used.

Example url:

https://example.org/index.php?id=12&redirect_url=https%3A%2F%2Fexample%2Eorg%2Fdestiny%2F
Copied!

Defined by Referrer

The referrer page is used for the redirect. This basically means that the user is sent back to the page he originally came from.

Defined by Domain entries

Same as Defined by Referrer, except that only the domains listed in plugin.tx_felogin_login.domains are allowed. If someone is sent to the login page coming from a domain which is not listed, the redirect will not happen.

By using the option Use First Supported Mode from Selection you can define several fallback methods.

Settings editor

New in version 13.3

The new backend module Site Management > Settings provides an overview of sites which offer configurable settings and makes them editable.

When the site set for the frontend login is included, the settings for EXT:felogin become available in the editor.

You can find the available site settings in module Site Management > Settings

You can change individual settings here. If the site settings are writable you can hit the Save button and the settings will be written directly to the site settings.

If the settings are not writable you can click the YAML export button to export the settings. These can then be added by a developer with sufficient rights.

The available settings are also described in detail in Settings for the "Frontend Login" site set.

Site set configuration of the Frontend Login

New in version 13.1

Site sets were added.

The system extension typo3/cms-felogin provides the site set "Frontend Login".

The different methods of setting are taking precedence in the following order:

Include the site set

Include the site set "Frontend Login" via the site set in the site configuration or the custom site package's site set.

Add the site set "Frontend Login"

This will change your site configuration file as follows:

config/sites/my-site/config.yaml (diff)
  base: 'https://example.com/'
  rootPageId: 1
  dependencies:
+   - typo3/felogin
    - typo3/fluid-styled-content-css
Copied!

If your site has a custom site package, you can also add the "Frontend Login" set as dependency in your site set's configuration:

EXT:my_site_package/Configuration/Sets/MySite/config.yaml (diff)
 name: my-vendor/my-site-package
 label: My Site Package Set
 settings:
   website:
     background:
       color: '#386492'
 dependencies:
+  - typo3/felogin
   - typo3/fluid-styled-content-css
Copied!

Settings for the "Frontend Login" site set

New in version 13.1

These settings were added with the site sets in TYPO3 v13.1.

See also: Example: Set the user storage page using the site set settings.

If you plan to migrate from TypoScript setup settings to site settings see Migration from TypoScript setup settings to site settings.

These settings can be adjusted in the Settings editor.

Settings of "Frontend Login"
Name Type Label
Frontend Login
string User Storage Page
string Recursive
bool Display Password Recovery Link
bool Display Remember Login Option
bool Disable redirect after successful lo...
string Email Sender Address
string Email Sender Name
string Reply-to email Address
string Date format
string Layout root path
string Template root path
string Partial root path
string Template name for emails.
string Redirect Mode
bool Use First Supported Mode from Select...
int After Successful Login Redirect to P...
int After Failed Login Redirect to Page
int After Logout Redirect to Page
bool Disable Redirect
int Time in hours how long the link for ...
string Allowed Referrer-Redirect-Domains
bool Expose existing users
string Path to template root (frontend)
string Path to template partials (frontend)
string Path to template layouts (frontend)

felogin

felogin
Label
Frontend Login

felogin.pid

felogin.pid
Type
string
Default
"0"
Label
User Storage Page
Category
Frontend Login

Define the Storage Folder with the Website User Records, using a comma separated list or single value

felogin.recursive

felogin.recursive
Type
string
Default
"0"
Label
Recursive
Enum
{ "0": "0", "1": "1", "2": "2", "3": "3", "4": "4", "255": "255" }
Category
Frontend Login

If set, also subfolder at configured recursive levels of the User Storage Page will be used

felogin.showForgotPassword

felogin.showForgotPassword
Type
bool
Default
false
Label
Display Password Recovery Link
Category
Frontend Login

If set, the section in the template to display the link to the forgot password dialog is visible.

felogin.showPermaLogin

felogin.showPermaLogin
Type
bool
Default
false
Label
Display Remember Login Option
Category
Frontend Login

If set, the section in the template to display the option to remember the login (with a cookie) is visible.

felogin.showLogoutFormAfterLogin

felogin.showLogoutFormAfterLogin
Type
bool
Default
false
Label
Disable redirect after successful login, but display logout-form
Category
Frontend Login

If set, the logout form will be displayed immediately after successful login.

felogin.emailFrom

felogin.emailFrom
Type
string
Label
Email Sender Address
Category
Frontend Login

email address used as sender of the change password emails

felogin.emailFromName

felogin.emailFromName
Type
string
Label
Email Sender Name
Category
Frontend Login

Name used as sender of the change password emails

felogin.replyToEmail

felogin.replyToEmail
Type
string
Label
Reply-to email Address
Category
Frontend Login

Reply-to address used in the change password emails

felogin.dateFormat

felogin.dateFormat
Type
string
Default
"Y-m-d H:i"
Label
Date format
Category
Frontend Login

Format for the link is valid until message (forgot password email)

felogin.email.layoutRootPath

felogin.email.layoutRootPath
Type
string
Label
Layout root path
Category
Frontend Login

Path to layout directory used for emails

felogin.email.templateRootPath

felogin.email.templateRootPath
Type
string
Default
"EXT:felogin/Resources/Private/Email/Templates/"
Label
Template root path
Category
Frontend Login

Path to template directory used for emails

felogin.email.partialRootPath

felogin.email.partialRootPath
Type
string
Label
Partial root path
Category
Frontend Login

Path to partial directory used for emails

felogin.email.templateName

felogin.email.templateName
Type
string
Default
"PasswordRecovery"
Label
Template name for emails.
Category
Frontend Login

HTML emails get the .html file extension, plaintext emails get the .txt file extension.

felogin.redirectMode

felogin.redirectMode
Type
string
Label
Redirect Mode
Category
Frontend Login

Comma separated list of redirect modes.\ Possible values: groupLogin, userLogin, login, getpost, referer, refererDomains, loginError, logout.\ Warning: redirects only work if neither the plugin nor the page it is displayed on are set to `hide at login`.

felogin.redirectFirstMethod

felogin.redirectFirstMethod
Type
bool
Default
false
Label
Use First Supported Mode from Selection
Category
Frontend Login

If set the first method from redirectMode which is possible will be used

felogin.redirectPageLogin

felogin.redirectPageLogin
Type
int
Default
0
Label
After Successful Login Redirect to Page
Category
Frontend Login

Page id to redirect to after Login

felogin.redirectPageLoginError

felogin.redirectPageLoginError
Type
int
Default
0
Label
After Failed Login Redirect to Page
Category
Frontend Login

Page id to redirect to after Login Error

felogin.redirectPageLogout

felogin.redirectPageLogout
Type
int
Default
0
Label
After Logout Redirect to Page
Category
Frontend Login

Page id to redirect to after Logout

felogin.redirectDisable

felogin.redirectDisable
Type
bool
Default
false
Label
Disable Redirect
Category
Frontend Login

If set redirecting is disabled

felogin.forgotLinkHashValidTime

felogin.forgotLinkHashValidTime
Type
int
Default
12
Label
Time in hours how long the link for forgot password is valid
Category
Frontend Login

How many hours the link for forgot password is valid

felogin.domains

felogin.domains
Type
string
Label
Allowed Referrer-Redirect-Domains
Category
Frontend Login

Comma separated list of domains which are allowed for the referrer redirect mode

felogin.exposeNonexistentUserInForgotPasswordDialog

felogin.exposeNonexistentUserInForgotPasswordDialog
Type
bool
Default
false
Label
Expose existing users
Category
Frontend Login

Expose the information on whether or not the account for which a new password was requested exists. By default, that information is not disclosed for privacy reasons.

felogin.view.templateRootPath

felogin.view.templateRootPath
Type
string
Label
Path to template root (frontend)
Category
Frontend Login

Path to template directory used for the plugin in the frontend. Extends the default template location.

felogin.view.partialRootPath

felogin.view.partialRootPath
Type
string
Label
Path to template partials (frontend)
Category
Frontend Login

Path to partial directory for the plugin in the frontend. Extends the default partial location.

felogin.view.layoutRootPath

felogin.view.layoutRootPath
Type
string
Label
Path to template layouts (frontend)
Category
Frontend Login

Path to layout directory used for the plugin in the frontend. Can be used to introduce a custom layout.

Migration from TypoScript setup settings to site settings

The site settings are named like the TypoScript constants used before site sets. However the TypoScript constants are not always named the same like the TypoScript setup settings.

For each TypoScript setup / FlexForm setting we list the corresponding site set setting in the overview table of the configuration values.

For example, the setting felogin.pid sets setting pages.

Bear that in mind when migrating from TypoScript setup to site set settings.

Example: Set the user storage page using the site set settings

After you included the site set you can use the site set settings to configure the frontend login plugin's behaviour and layout site-wide.

See also Adding site settings.

You can add the settings to your Site settings or to the settings of your custom site package extension.

To add the settings to your site settings, edit the file config/sites/<my_site>/settings.yaml in Composer-based installations or typo3conf/sites/<my_site>/settings.yaml in legacy installations. If the file does not exist yet, create one. Use the setting felogin.pid to set the storage folder. If its subfolders should also be included, additionally use setting felogin.recursive.

config/sites/<my_site>/settings.yaml | typo3conf/sites/<my_site>/settings.yaml
felogin:
  pid: 42
  recursive: 255

Copied!

TypoScript configuration of the Frontend Login

TypoScript setup / FlexForm settings

Most of these plugin settings can be set with the following methods, the top bottom most taking precedence:

See also Example: Override the default storage page in the plugin's FlexForm.

showForgotPassword

showForgotPassword
Type
bool

If set, the section in the template to display the link to the forgot password dialogue is visible.

showPermaLogin

showPermaLogin
Type
bool

If set, the section in the template to display the option to remember the login (with a cookie) is visible.

showLogoutFormAfterLogin

showLogoutFormAfterLogin
Type
bool

If set, the logout form will be displayed immediately after successful login.

pages

pages
Type
string
Site set setting
felogin.pid
TypoScript Constant
{$styles.content.loginform.pid}

Define the User Storage Page with the Website User Records, using a comma separated list or a single value (page id).

recursive

recursive
Type
int
Site set setting
felogin.recursive
TypoScript Constant
{$styles.content.loginform.recursive}

If set, also any subfolders of the User Storage Page will be used at configured recursive levels

redirectMode

redirectMode
Type
string
Site set setting
felogin.redirectMode
TypoScript Constant
{$styles.content.loginform.redirectMode}

Comma separated list of redirect modes. Possible values: groupLogin, userLogin, login, getpost, referer, refererDomains, loginError, logout See section on redirect modes for details.

redirectFirstMethod

redirectFirstMethod
Type
bool
Site set setting
felogin.redirectFirstMethod
TypoScript Constant
{$styles.content.loginform.redirectFirstMethod}

If set the first method from redirectMode which is possible will be used

redirectPageLogin

redirectPageLogin
Type
integer
Site set setting
felogin.redirectPageLogin
TypoScript Constant
{$styles.content.loginform.redirectPageLogin}

Page id to redirect to after Login

redirectPageLoginError

redirectPageLoginError
Type
integer
Site set setting
felogin.redirectPageLoginError
TypoScript Constant
{$styles.content.loginform.redirectPageLoginError}

Page id to redirect to after Login Error

redirectPageLogout

redirectPageLogout
Type
integer
Site set setting
1
TypoScript Constant
{$styles.content.loginform.redirectPageLogout}

Page id to redirect to after Logout

redirectDisable

redirectDisable
Type
bool
Site set setting
felogin.redirectPageLogout
TypoScript Constant
{$styles.content.loginform.redirectDisable}

If set redirecting is disabled

dateFormat

dateFormat
Type
date-conf
Site set setting
felogin.dateFormat
TypoScript Constant
Y-m-d H:i

Format for the link is valid until message (forgot password email)

email_from

email_from
Type
string

Email address used as sender of the change password emails

email_fromName

email_fromName
Type
string

Name used as sender of the change password emails

email

email

email.templateName

email.templateName
Type
string
Site set setting
felogin.email.templateName
TypoScript Constant
{$styles.content.loginform.email.templateName}

Template name for emails. Plaintext emails get the .txt file extension.

email.layoutRootPaths

email.layoutRootPaths
Type
array
Site set setting
felogin.email.templateRootPath
TypoScript Constant
{$styles.content.loginform.email.layoutRootPath}

Path to layout directory used for emails

email.templateRootPaths

email.templateRootPaths
Type
array
Site set setting
felogin.email.templateRootPath
TypoScript Constant
{$styles.content.loginform.email.templateRootPaths}

Path to template directory used for emails

email.partialRootPaths

email.partialRootPaths
Type
array
Site set setting
felogin.email.partialRootPath
TypoScript Constant
{$styles.content.loginform.email.partialRootPaths}

Path to partial directory used for emails

exposeNonexistentUserInForgotPasswordDialog

exposeNonexistentUserInForgotPasswordDialog
Type
bool
Site set setting
felogin.exposeNonexistentUserInForgotPasswordDialog
TypoScript Constant
{$styles.content.loginform.exposeNonexistentUserInForgotPasswordDialog}

If set and the user account cannot be found in the forgot password dialogue, an error message will be shown that the account could not be found. .. warning:: Enabling this will disclose information about whether an email address is actually used for a frontend user account! Visitors can find out if a user is known as frontend user.

forgotLinkHashValidTime

forgotLinkHashValidTime
Type
integer
Site set setting
felogin.forgotLinkHashValidTime
TypoScript Constant
{$styles.content.loginform.forgotLinkHashValidTime}

Time in hours how long the link for forgot password is valid

domains

domains
Type
string

Comma separated list of domains which are allowed for the referrer redirect mode

Example: Set the default storage page via TypoScript constant

You can use the TypoScript provider or other means of setting the TypoScript constants.

Changed in version 13.1

config/sites/MySite/constants.typoscript
styles.content.loginform {
  pid = 42
  recursive = 255
}
Copied!

Example: Set the default storage page via TypoScript setup

In order to set the default storage page to a more dynamic value, use the TypoScript setup. Use the TypoScript provider or other means of ref:setting the TypoScript setup <t3tsref:using-and-setting>.

config/sites/MySite/constants.typoscript
[{$tx_my_extension.settings.feature1Enabled} == 1]
  plugin.tx_felogin_login.settings.pid = 123
[ELSE]
  plugin.tx_felogin_login.settings.pid = 42
[END]
Copied!

Example: Override the default storage page in the plugin's FlexForm

If you set any FlexForm setting within the content element representing the plugin to a non-empty value it will override any other setting not matter if it is made via site settings, TypoScript constant ot TypoScript setup. Empty values take no effect if a default was set by other means.

In the backend module Web > Page edit the content element containing the login form. Go to tab Plugin and sub tab General. You should see a form similar to the following:

A screenshot showing the "General" tab of the plugin settings

Settings in the tab General of the plugin tab

Choose the desired page or pages in the field with label User Storage Page (key settings.pages).

A screenshot showing FlexForm Field with key `settings.pages`

The corresponding FlexForm field settings.pages in backend debug mode.

GET and POST parameters

The extension uses several GET and POST parameters to define or override redirect settings.

noredirect

Parameter
noredirect
Evaluation
GET and POST
Data type
string
Description
If set to 1, no redirect will be processed after a successful login.

PSR-14 events

The following PSR-14 events are available to extend the extension:

AfterUserLoggedInEvent

Trigger any kind of action when a frontend user has been successfully logged in. More details

BeforeRedirectEvent

Notification before a redirect is made. More details

LoginConfirmedEvent

A notification when a log in has successfully arrived at the plugin, via the view and the controller, multiple information can be overridden in event listeners. More details

LoginErrorOccurredEvent

A notification if something went wrong while trying to log in a user. More details

LogoutConfirmedEvent

A notification when a log out has successfully arrived at the plugin, via the view and the controller, multiple information can be overridden in event listeners. More details

ModifyLoginFormViewEvent

Allows to inject custom variables into the login form. More details

PasswordChangeEvent

Event that contains information about the password which was set, and is about to be stored in the database. More details

SendRecoveryEmailEvent

Event that contains the email to be sent to the user when they request a new password. More details

Examples

In this section some common situations are described:

Send visitors to login page and redirect to original page

A common situation is that visitors who go to a page with access restrictions should go to a login page first and after logging in should be send back to the page they originally requested.

Assume we have a login page with id 2.

Using TypoScript we can still display links to access restricted pages and send visitors to the login page:

config {
    typolinkLinkAccessRestrictedPages = 2
    typolinkLinkAccessRestrictedPages_addParams = &return_url=###RETURN_URL###
}
Copied!

On the login page the login form must be configured to redirect to the original page:

plugin.tx_felogin_login.settings.redirectMode = getpost
Copied!

(This option can also be set in the flexform configuration of the felogin content element)

If visitors will directly enter the URL of an access restricted page they will be sent to the first page in the rootline to which they have access. Sending those direct visits to a login page is not a job of the felogin plugin, but requires a custom page-not-found handler. In this sense, we refer to Custom error handler implementation for 403 redirects.

Custom error handler implementation for 403 redirects

This section explains how to utilize a custom error handler to catch 403 restricted page errors and allow to forward to a login form, and then redirect back to the originating page after successful login.

  1. You need the following site settings in the error handling

    Error Handling tab of Site Configuration module

    There you add the custom 403 error handler and configure the error handler, you create in the following steps.

  2. Look up the page ID where a login form (like with EXT:felogin) is placed

    This page ID is needed in the following step, so that the error handler will know, where to forward an unauthenticated user to, so that a login can be performed.

    Ideally, this should be done by configuring a page ID via the site settings, and referring back to a named ID. See PHP API: accessing site configuration for more information. For reduced complexity, this example uses a hard-coded page ID.

  3. Create a new error handler RedirectLoginErrorHandler.php

    Create a PHP error handler class like the following in a custom extension, like your own sitepackage:

    EXT:my_sitepackage/Classes/Error/PageErrorHandler/RedirectLoginErrorHandler.php
    <?php
    
    declare(strict_types=1);
    
    /*
     * This file is part of the TYPO3 CMS project.
     *
     * It is free software; you can redistribute it and/or modify it under
     * the terms of the GNU General Public License, either version 2
     * of the License, or any later version.
     *
     * For the full copyright and license information, please read the
     * LICENSE.txt file that was distributed with this source code.
     *
     * The TYPO3 project - inspiring people to share!
     */
    
    namespace MyVendor\MySitePackage\Error\PageErrorHandler;
    
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\ServerRequestInterface;
    use TYPO3\CMS\Core\Context\Context;
    use TYPO3\CMS\Core\Controller\ErrorPageController;
    use TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface;
    use TYPO3\CMS\Core\Http\HtmlResponse;
    use TYPO3\CMS\Core\Http\RedirectResponse;
    use TYPO3\CMS\Core\LinkHandling\LinkService;
    use TYPO3\CMS\Core\Site\Entity\Site;
    use TYPO3\CMS\Core\Utility\GeneralUtility;
    use TYPO3\CMS\Frontend\Page\PageAccessFailureReasons;
    
    /**
     * An error handler that redirects to a configured page, where the login
     * process is handled. Passes a configurable URL parameter (`return_url` or
     * `redirect_url`) to the target page.
     */
    final class RedirectLoginErrorHandler implements PageErrorHandlerInterface
    {
        private const PAGE_ID_LOGIN_FORM = 656;
    
        private readonly int $loginRedirectPid;
        private readonly string $loginRedirectParameter;
        private readonly Context $context;
        private readonly LinkService $linkService;
        private readonly ErrorPageController $errorPageController;
    
        public function __construct(private readonly int $statusCode)
        {
            $configuration = [
                // TODO: Replace with $siteSettings[...] or something else
                'loginRedirectTarget' => 't3://page?uid=' . self::PAGE_ID_LOGIN_FORM,
                'loginRedirectParameter' => 'return_url',
            ];
    
            $this->context = GeneralUtility::makeInstance(Context::class);
            $this->linkService = GeneralUtility::makeInstance(LinkService::class);
            $this->errorPageController = GeneralUtility::makeInstance(ErrorPageController::class);
    
            $urlParams = $this->linkService->resolve($configuration['loginRedirectTarget']);
            $this->loginRedirectPid = (int)($urlParams['pageuid'] ?? 0);
            $this->loginRedirectParameter = $configuration['loginRedirectParameter'];
        }
    
        public function handlePageError(
            ServerRequestInterface $request,
            string $message,
            array $reasons = []
        ): ResponseInterface {
            $this->checkHandlerConfiguration();
    
            if ($this->shouldHandleRequest($reasons)) {
                return $this->handleLoginRedirect($request);
            }
    
            // Show general error message with a 403 HTTP status code
            return $this->getGenericAccessDeniedResponse($message);
        }
    
        private function getGenericAccessDeniedResponse(string $reason): ResponseInterface
        {
            $reason = $reason ? ' Reason: ' . $reason : '';
            $content = $this->errorPageController->errorAction(
                'Page Not Found',
                sprintf('The page did not exist or was inaccessible.%s', $reason),
                0,
                $this->statusCode,
            );
            return new HtmlResponse($content, $this->statusCode);
        }
    
        private function handleLoginRedirect(ServerRequestInterface $request): ResponseInterface
        {
            if ($this->isLoggedIn()) {
                return $this->getGenericAccessDeniedResponse(
                    'The requested page was not accessible with the provided credentials'
                );
            }
    
            /** @var Site $site */
            $site = $request->getAttribute('site');
            $language = $request->getAttribute('language');
    
            $loginUrl = $site->getRouter()->generateUri(
                $this->loginRedirectPid,
                [
                    '_language' => $language,
                    $this->loginRedirectParameter => (string)$request->getUri(),
                ]
            );
    
            return new RedirectResponse($loginUrl);
        }
    
        private function shouldHandleRequest(array $reasons): bool
        {
            if (!isset($reasons['code'])) {
                return false;
            }
    
            $accessDeniedReasons = [
                PageAccessFailureReasons::ACCESS_DENIED_PAGE_NOT_RESOLVED,
                PageAccessFailureReasons::ACCESS_DENIED_SUBSECTION_NOT_RESOLVED,
            ];
            $isAccessDenied = in_array($reasons['code'], $accessDeniedReasons, true);
    
            return $isAccessDenied || $this->isSimulatedBackendGroup();
        }
    
        private function isLoggedIn(): bool
        {
            if ($this->context->getPropertyFromAspect('frontend.user', 'isLoggedIn')) {
                return true;
            }
            return $this->isSimulatedBackendGroup();
        }
    
        protected function isSimulatedBackendGroup(): bool
        {
            if (!$this->context->getPropertyFromAspect('backend.user', 'isLoggedIn')) {
                return false;
            }
            // look for special "any group"
            $groups = $this->context->getPropertyFromAspect('frontend.user', 'groupIds');
            return $groups[1] === -2;
        }
    
        private function checkHandlerConfiguration(): void
        {
            if ($this->loginRedirectPid === 0) {
                throw new \RuntimeException('No loginRedirectTarget configured for LoginRedirect errorhandler', 1700813537);
            }
    
            if ($this->statusCode !== 403) {
                throw new \RuntimeException(sprintf('Invalid HTTP status code %d for LoginRedirect errorhandler', $this->statusCode), 1700813545);
            }
        }
    }
    
    Copied!

    Adapt the constant PAGE_ID_LOGIN_FORM to match the page ID from the previous step. Since there is no proper way how to do it otherwise, we put in the page ID of the login form hard-coded into the file RedirectLoginErrorHandler.php and define a constant PAGE_ID_LOGIN_FORM for it. In the example above, this is set to 656.

  4. In your EXT:felogin plugin, make sure you selected "Defined by GET/POST Parameters" as first redirect mode

    Plugin > Redirects tab of Login Form content element

    You need to configure the login form that receives your redirect in a way, that allows to evaluate submitted URL parameters. In EXT:felogin, this is achieved via this Redirect Mode (which can also be set through TypoScript configuration, see redirectMode.

    Your login form will probably also need to define a specific target page for normal logins (independent from the error handler redirect), so you should also add a redirectMode like login to your list, and set a target page in redirectPageLogin.

  5. Testing the custom error handler

    Clear the caches, for example via the backend module Admin Tools > Maintenance.

    Then open any access-restricted page in an incognito browser window to be sure that you are not logged in yet. Here we will use the example URL https://example.org/restricted/page.

    When everything is configured correctly and if you are not logged in yet, then you should be redirected to your login page like https://example.org/login (example page ID 656).

    After entering proper frontend user credentials, you should be redirected back to https://example.org/restricted/page, the page where you wanted to get to initially.

This example was taken from [FEATURE] Introduce ErrorHandler for 403 errors with redirect option which works in TYPO3 v11 and v12, and has been integrated to TYPO3 v13, where it can be used without a custom implementation.

Known Problems

  • If there is more than one felogin plugin on a page the password recovery option can cause problems. This is a general problem with plugins, but in this case the cause is a small hash in the forgot password form which is stored in the frontend user session data. With multiple instances on a page only one of the hashes is stored and only one of the forgot password forms will work. Make sure there is only one felogin plugin on the page where the password recovery form is displayed.
  • If usergroup access rights of the plugin are defined to Hide at login, all felogin code (e.g. redirects, PSR-14 events) will not be executed after a user successfully logged in.

Sitemap