---
title: actionAuthentication
section: hooks
slug: actionAuthentication
hook_type: action
category: customer
location: FO
since_version: 1.5
source_url: "https://ayudaprestashop.es/hooks/actionAuthentication"
---

# Hook `actionAuthentication`

| Propiedad | Valor |
| --- | --- |
| Tipo | Action |
| Localizacion | FO |
| Categoria | customer |
| Desde version | 1.5 |

## Descripcion

Se ejecuta cada vez que un cliente inicia sesion exitosamente en el front office. Permite registrar accesos, actualizar datos de ultima conexion, sincronizar sesiones con sistemas externos o implementar logica de seguridad como deteccion de accesos sospechosos.

## Parametros

| Nombre | Tipo | Requerido | Descripcion |
| --- | --- | --- | --- |
| `customer` | `Customer` | si | Objeto Customer del cliente que acaba de iniciar sesion |

## Valor de retorno

- **Tipo**: `void`
- **Descripcion**: Este hook no espera valor de retorno

## Disparado por

| Contexto | Clase | Metodo | Fichero |
| --- | --- | --- | --- |
| AuthController | `AuthController` | `processSubmitLogin()` | `controllers/front/AuthController.php` |

**Paginas**: `authentication`, `my-account`

## Registro del hook

```php
<?php
public function install()
{
    return parent::install()
        && $this->registerHook('actionAuthentication');
}
```

## Ejemplo de uso

```php
<?php
/**
 * Hook actionAuthentication — cliente inicia sesion
 */
public function hookActionAuthentication(array $params)
{
    /** @var Customer $customer */
    $customer = $params['customer'];

    // Ejemplo: Registrar log de acceso con IP y user-agent
    $ip = Tools::getRemoteAddr();
    $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';

    Db::getInstance()->insert('mymodule_login_log', [
        'id_customer' => (int) $customer->id,
        'email'       => pSQL($customer->email),
        'ip_address'  => pSQL($ip),
        'user_agent'  => pSQL(substr($userAgent, 0, 255)),
        'date_add'    => date('Y-m-d H:i:s'),
    ]);

    // Ejemplo: Detectar login desde nueva IP (seguridad)
    $knownIPs = Db::getInstance()->executeS(
        'SELECT DISTINCT ip_address FROM `' . _DB_PREFIX_ . 'mymodule_login_log`
         WHERE id_customer = ' . (int) $customer->id . '
         AND ip_address != "' . pSQL($ip) . '"
         ORDER BY date_add DESC LIMIT 10'
    );

    if (!empty($knownIPs)) {
        $known = array_column($knownIPs, 'ip_address');
        if (!in_array($ip, $known) && count($known) > 0) {
            // Nueva IP detectada — enviar alerta al cliente
            Mail::send(
                (int) $customer->id_lang,
                'new_login_alert',
                Mail::l('Nuevo acceso a tu cuenta'),
                ['customer_name' => $customer->firstname, 'ip' => $ip],
                $customer->email,
                $customer->firstname . ' ' . $customer->lastname,
                null,
                null,
                null,
                null,
                _PS_MODULE_DIR_ . $this->name . '/mails/'
            );
        }
    }
}
```

## Notas y gotchas

- Este hook solo se dispara en login exitoso — no en intentos fallidos.
- Solo se ejecuta en el front office. Para el back office no existe un hook equivalente directo.
- El cliente ya esta autenticado cuando se ejecuta el hook — la sesion esta activa.
- No confundir con actionCustomerAccountAdd que es solo para nuevos registros.
- En PS 1.7+ con el checkout de un paso, el login puede ocurrir durante el proceso de compra.

## Hooks relacionados

- [`actionCustomerAccountAdd`](https://ayudaprestashop.es/hooks/actionCustomerAccountAdd)
- [`displayCustomerAccount`](https://ayudaprestashop.es/hooks/displayCustomerAccount)

## Guias relacionadas

- [modules/main-file](https://ayudaprestashop.es/modules/main-file)
- [customers/customer-lifecycle](https://ayudaprestashop.es/customers/customer-lifecycle)

## Historial de versiones

| Version | Cambio |
| --- | --- |
| 1.5 | Introducido con el parametro customer |
| 1.7 | Sin cambios. Compatible con PS 1.7, 8.x y 9.x |


---

*Fuente: [https://ayudaprestashop.es/hooks/actionAuthentication](https://ayudaprestashop.es/hooks/actionAuthentication). Version Markdown generada automaticamente para consumo por LLMs.*
