The postLogin
hook is triggered after a user has logged in. This can
be either in the back end or the front end. It passes the user object
as argument and does not expect a return value.
Using the postLogin
hook has been deprecated and will no longer work in Contao 5.0.
You can use the security.interactive_login
event instead for example.
\Contao\User $user
The back end or front end user (object) which has been logged in.
// src/EventListener/PostLoginListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\User;
#[AsHook('postLogin')]
class PostLoginListener
{
public function __invoke(User $user): void
{
if ($user instanceof \Contao\FrontendUser) {
// Do something with the front end user $user
}
}
}