I have a headless application written in yii, with an Angular application using the yii2 api. Currently I’m using local storage for tokens, but I read this link and would like to store the token in a cookie.
if (($cookie = $cookies->get('token')) !== null) {
die('Token found in cookie');
$token = $parser->parse($cookie->value);
}
Using the native PHP $_COOKIE the cookie can be read by the yii2 application, but the setcookie() does not work. It looks like the yii2-rest controller strips away the headers before sending the response.
The token is always null, so it seems like cookies are disabled by default in Rest controllers / JSON responses, how can I enable this?
Its still stateless when using a JWT token, its just safer storage in cookies.
I have not set any rest-specific config settings other than url rules. And I’ve tried turning sessions back on in the user-config (‘enableSession’ => true). Do you know if cookies are disabled by default in rest controllers?
EDIT:
for clarity, I’m testing all endpoints in POSTman and I have a backend HTML-based application as well (working with regular sessions and cookies out-of-the-box).