When I do a POST method to my PHP backend, I receive this response, but is there a way to just grab the object from the response.data?
<br />
<b>Warning</b>: Undefined array key "session_id" in <b>/home/cs/experimetns/RunnerMaps/RunnerMapPrototype/api/index.php</b> on line <b>9</b><br />
<br />
<b>Notice</b>: session_start(): Ignoring session_start() because a session is already active in <b>/home/cs/experimetns/RunnerMaps/RunnerMapPrototype/api/index.php</b> on line <b>11</b><br />
{"success":"Login successful","role":"admin","session_id":"4kj0sflsnevp520ebitdq5iev1"}
When I do a respone.data[0], it results to a "<" and I am not able to do response.data["role"] since it sees it as a string.
Here is my Axios call using React.
await Axios.post(currentUrl, params).then((response) => {
if (response.data["error"]) {
alert(response.data["error"]);
} else {
//
console.log(response.data);
localStorage.setItem("session_id", response.data["session_id"]);
localStorage.setItem("role", response.data["role"]);
if (response.data["role"] == "admin") {
navigate("/admin");
} else {
navigate("/user");
}
}
});
There isn't any way to touch the PHP code, so I can't just check if I have a session. This is what I will always receive, but I only want
{"success":"Login successful","role":"admin","session_id":"4kj0sflsnevp520ebitdq5iev1"}