Where is other domain, is it a subdomain. See https://laracasts.com/discuss/channels/laravel/subdomain-single-auth-across-all-subs-main-not-working
Ajax request to other domain to get user info data
Hi:
I have my maindomain.com project.
In other site othersite.com, I want to show an icon if the user is logged in the maindomain.com
I do an Ajax request, and do the CORS stuff (by the way, this library works perfectly https://github.com/fruitcake/laravel-cors)
But when I request the ajax from othersite.com to the URL maindomain.com/check-user, I don't get the right information.
That controller is simple:
return (Auth::check() ? 1 : 0)
NOTE: Well, actually this is the test ... in the real world I will return the name and avatar so they will just click on it and go from othersite.com to maindomain.com ;-)
But as I said, ajax is returning 0
If I go in the same browser to maindomain.com/check-user... it returns 1, since I'm logged !!!
What can be happening?
By the way,
- ajax request is using xhrFields: { withCredentials: true },
- Access-Control-Allow-Origin, Access-Control-Allow-Headers and Access-Control-Allow-Methods headers are not using wildcard (as suggested here: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#requests_with_credentials)
Please or to participate in this conversation.