I'm facing an issue, that the cookie does not attach to the browser after a successful request. However, as I see it comes successfully with the response. I've looked at many examples, but none of them worked for me, probably missing something with configuration. The most legit solutions looked these ones for me this and this, but it didn't work for me. I'm using Laravel and Vue as separate apps. I've tried to send back cookies with Cookie::queue() and with ->withCookie(); - nothing. Also, I've tried to change sameSite to none - nothing again. Overall, I can see them in response, but not in the 'Application' tab. Important to mention that the cookies attach perfectly in the postman.
Cookie::queue('access_token', 'test', $minutes = 30000, $path = null, $domain = null, $secure = false, $httpOnly = false, true, $sameSite = 'none');
return $this->successfullRequest($user, 'User successfully logged in');
Another way how I tried to send them:
return $this->successfullRequest($user, 'User successfully logged in')->withCookie($tokens['refresh_token']);
This is my cors.php file:
return [
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => true,
];
This is my request from Vue
// Send the request to API
const response = await fetch('http://127.0.0.1:8000/api/v1/auth/login', {
method: "POST",
credentials: 'include',
headers: {
Accept: 'application/vnd.api+json',
'Content-Type': 'application/vnd.api+json'
},
body: JSON.stringify({
email: credentials.email,
password: credentials.password
})
});