Umang Galaiya
Umang Galaiya

Reputation: 712

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?

Upvotes: 1

Views: 289

Answers (1)

Umang Galaiya
Umang Galaiya

Reputation: 712

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

Added

xhrFields: {
       withCredentials: true
}

and it worked.

Upvotes: 0

Related Questions