Authentication fails in release mode
I'm using this library inside my react-native based application and I just found a weird bug when the debug mode is off. Everything works just fine and as expected when I'm turning on the debug mode but If I turn off the debug mode, the authentication function is failing somehow.
this is how I initialised my instance:
import WPAPI from 'wpapi';
const wpapi = new WPAPI({
endpoint: 'https://mydomain.com/wp-json',
username: 'username',
password: 'password,
});
wpapi.posts = wpapi.registerRoute('wp/v2', '/posts/(?P<id>)');
and in here's my action:
export function fetchPosts(currentPage = 1) {
return (dispatch) => {
dispatch(requestPosts());
return wpapi.posts().perPage(50).page(currentPage)
.embed()
.get((err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
};
}
The protected fields are only being fetched when the debug mode is on! I also tried following solution to manually force the authentication:
wpapi.posts().auth({username: 'username', password: 'password'}).perPage(50).page(currentPage)
.embed()
.get((err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
but it doesn't change the behaviour!
any help would be greatly appreciated 🙏🏻
@el-lsan this helps me...
https://github.com/WP-API/Basic-Auth/issues/35#issuecomment-244001216
I'm afraid I don't have any obvious solution to offer. I am not personally experienced with React Native, but I would assume (as you have) that this should not change how the authentication gets sent. Can you test with a proxy to see whether the authorization header is being passed from your application at all?
I know it's a hassle, but given my lack of familiarity with React Native, to go further I'd need to ask for a reduced test case demonstrating the bug that I could pull down and experiment with.