1

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?

2
  • when you use postman, do you provide a username/password? if so, you need to do the same with fetch Commented Jan 12, 2017 at 17:34
  • I do not provide a username or pass in postman Commented Jan 12, 2017 at 19:15

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

1 Comment

Im actually calling it like 'secret:[email protected]/v1/login/signup'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.