Any POST request to the wp rest api yields 404 responses, yet when switched to GET everything works fine.
The react component's method to handle a form submit with fetch:
handleFormSubmit(){
event.preventDefault();
const data = new FormData(event.target);
fetch('sfg/wp-json/sfg/v1/login', {
method : 'POST',
body: data
})
.then( (res) => {
console.log(res);
} );
}
The register route function:
register_rest_route( 'sfg/v1', '/login/', array(
'methods' => 'POST',
'callback' => 'json_login'
));
The callback:
function json_login(){
$credentials = array();
$credentials['user_name'] = $_POST['username'];
$credentials['password'] = $_POST['password'];
$status = wp_signon($credentials, false);
return $status;
}
App is sending the request from a different port - 8081 rather than 8080.