0

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']);

Attaching image from response image

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
        })
    });
henrbu
  • 137
  • 10

1 Answers1

1

After reading tons of stackoverflow posts and other documentation I understood that I can't set a cookie from another domain. The issue was that my Laravel app was running on 127.0.0.1 and Vue app from localhost:5000, so what I basically did I launched Laravel app with php artisan serve --host localhost:3000 and that solved the problem because I was able to set the cookie from the same host.

henrbu
  • 137
  • 10