I am working on an application that uses ReactJS. I will be running the application on a TomCat server and deploying using Maven. For past applications I have used j_security_check to authenticate users and would like to authenticate users in the React app the same way.
My problem arises in that I am not sure how to set up my web.xml file to restrict access and prompt for a login. Since React only has one html file, and one js file, how do I restrict access and redirect to a different component? Do I need to have a separate html page for my login?
If this is something that has to be done programmatically, how would I go about setting up a HttpRequest to do this that would be secure? I have tried the following code, but am getting a 404 error when I try to login.
handleSub(fields) {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "j_security_check", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("j_username=fields.username&j_password=fields.password");}