Cookies Authentication in react JS

Viewed 21

I have an API that I don't have access to. The lack of documentation makes complicated to understand how it works. The only info I have, says that the authentication is through cookies, sending username and password parameters:

-Session based-url: https://example.api.com/, POST parameters: username, password-Authenticated -Session lasts 1 day

We achieved this in older projects with C# and RestClient like this:

var client = new RestClient($"{keys.ServiceURI}");
CookieContainer _cookieJar = new CookieContainer();
client.CookieContainer = _cookieJar;

var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter(
    "application/x-www-form-urlencoded", 
    $"username={keys.LoginId}&password={keys.LoginPass}", 
    ParameterType.RequestBody 
);
            
IRestResponse response = client.Execute(request);

When I try to fetch the url with javascript, the response is the login HTML page and the response status is 200 Ok

Could any of you guide me how to do this in reactJs? Thank you so much in advance

0 Answers
Related