'Log in Employee from module in PrestaShop

I have created a module to sign in Employee from an external site in REST like this:

A JSON Post with Authentication token and login/pass => module validate and answer an url with a JWT token like: https://example.com/module/ps_extern_auth/login_jwt?token=FyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cuY2FtYS16b25lLmZyIiwiZXhwIjoxNjQzOTA4NjIyLCJlbWFpbCI6ImcubGF0b3JyZUBldmVybGF0cy5jb20iLCJzdWIiOiI0NiJ9.lojt_J1LzeOWYYFCHn5xIuEka-FaEw5OOGk25VXAfNk

When this JWT token is validated, I write this code to login employee:

            $this->context->employee->remote_addr = ip2long(Tools::getRemoteAddr());
            // Update cookie
            $cookie = Context::getContext()->cookie;
            $cookie->id_employee = $this->context->employee->id;
            $cookie->email = $this->context->employee->email;
            $cookie->profile = $this->context->employee->id_profile;
            $cookie->passwd = $this->context->employee->passwd;
            $cookie->remote_addr = $this->context->employee->remote_addr;
            $cookie->write();

Which is the code get from AdminLoginController.php If I var_dump $cookie, I have correct informations. But then, when the employee go to /admin123456/index.php?controller=AdminProducts He is redirected to login page (He's not logged in).

Do I forget something? Thanks for your help.

PrestaShop 1.6 / PHP 7



Solution 1:[1]

The solution:

    /*            $cookie = Context::getContext()->cookie; */
            $cookie = new Cookie('psAdmin');

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guillaume