Support the ongoing development of Laravel.io →
Authentication Session
Last updated 2 years ago.
0

I figured out what was wrong and wanted to post in case it will help anyone else.

My issue was that I needed to set the credentials in order for the cross domain cookies to work. So I had to change my laravel-cors config to:

return [
    'supportsCredentials' => true,
    'allowedOrigins' => ['*'],
    'allowedHeaders' => ['*'],
    'allowedMethods' => ['GET', 'POST', 'PUT',  'DELETE'],
    'exposedHeaders' => [],
    'maxAge' => 0,
    'hosts' => [],
];

And then in my AJAX request, I had to add the appropriate parameter:

$.ajax({
    type: 'POST',
    url: 'http://api.subdomain.com/auth/login',
    xhrFields: {
        withCredentials: true
    },
    data: {
        'email': $('#email').val(),
        'password': $('#password').val()
    },
    success: function(response){
        console.log(response);
    }
});
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.