Umang Galaiya Umang Galaiya - 1 year ago 89
React JSX Question

Can't log in with Laravel and ReactJS using custom REST API

I have made an API with Laravel. There are three URLs, one to check whether the user is logged in or not (GET), one to log in (POST), and one to log out (GET).

I tried the APIs with Postman, and they work just fine. The order of my trying is: Check, Log in, check again. The results are False, ID#, True - in that order.

Now, I created a simple UI in React with three buttons, each one calls a function that implements the respective AJAX request. When I check the status of the user after logging in, it always returns False. I don't seem to find where the problem is. Can anyone help?

Answer Source

jQuery's AJAX didn't send the cookies by default, so I had to add an option to the AJAX call.


xhrFields: {
       withCredentials: true

and it worked.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download