1
votes

So I able to successfully send a request via postman, but whenever I throw it into fetch I get back a 401 error.

export const createUser = () => {
 return async (dispatch) => {
 dispatch({ type: CREATE_USER });

console.log('we are in the create user function');

try {
  let response = await fetch('secret.com/v1/login/signup', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      email: '[email protected]',
      password: 'Asadasd123123',
      first_name: 'joe',
      last_name: 'doe',
      phone_number: '373738'
    })
  });
  console.log('response ' + JSON.stringify(response));
} catch (error) {
  console.log(error);
}
  };
};

Here is the error I keep receiving. response {"type":"default","status":401,"ok":false,"headers":{"map":{"access-control-allow-methods":["GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS"],"access-control-allow-origin":["*"],"connection":["keep-alive"],"access-control-allow-credentials":["true"],"content-length":["188"],"content-type":["text/html; charset=utf-8"],"access-control-allow-headers":["Content-Type, Accept, Authorization"],"www-authenticate":["Basic realm=\"Restricted\""],"date":["Thu, 12 Jan 2017 16:57:58 GMT"],"server":["nginx"]}},"url":"https://secret.com/v1/login/signup","_bodyInit":{},"_bodyBlob":{}}

My backend developer believes I ran into a cross domain issue and need to setup a proxy server? "set up some proxy server (I would recommend nginx) that would proxy ajax queries to our API domain"

I think it has something to do with fetch? Ideas?

1
when you use postman, do you provide a username/password? if so, you need to do the same with fetchFuzzyTree
I do not provide a username or pass in postmanSamuel Krut

1 Answers

1
votes

I believe you need to provide the protocol, change:

await fetch('secret.com/v1/login/signup'...

to

await fetch('http://secret.com/v1/login/signup'