1

Backand return error this when I run the signUp method... enter image description here

Here's the signup method...

function signUp(firstName, lastName, email, password) {
    var canceller = $q.defer();
    var cancel = function(reason) {
      canceller.resolve(reason);
    };
    var promise = $http({
      method: 'POST',
      url: CONSTS.backandUrl + '/user/signup',
      data: {
        firstName: firstName,
        lastName: lastName,
        email: email,
        password: password
      },
      timeout: canceller.promise,
      ignoreLoadingBar: true
    });
    return {
      promise: promise,
      cancel: cancel
    };
  }

I have set the sign up and even the anonymous token as per the documentation.

function(BackandProvider, CONSTS) {
    BackandProvider.setAnonymousToken(CONSTS.anonymousToken);
    BackandProvider.setSignUpToken(CONSTS.signUpToken);
    BackandProvider.setAppName(CONSTS.appName);
}

Am I missing something? Would appreciate a point in the right direction.

Ingadi
  • 563
  • 1
  • 7
  • 20
  • Your clue is in the error message: `No 'Access-Control-Allow-Origin' header is present on the requested resource.` Basically, you are not allowed to make cross-domain requests by default, it is unsafe. I would try using JSONP, it is a sort of "hack" to get around this. I'm not sure completely how it works and this topic is still a bit fuzzy to me, but check this link out for more info: http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource – Jordan Jun 21 '16 at 21:19
  • Thanks @Jordan You were right it was a security issue.Seems you need to include a sign up token as a header along with the request. From the docs 'The parameters for the sign-up call are: * SignUpToken - A security token to prevent malicious attacks. this should be added to the header *' – Ingadi Jun 23 '16 at 17:08

1 Answers1

2

This is a common issue for ajax calls through javascript. It happens because cross domain requests are not permitted through javascript ajax calls. In your case you are doing a request from domain localhost to api.backend.com. Browser checks if the server you are requesting has a header Access-Control-Allow- Origin set in the response headers. If not present, or the value of the header doesn't contain your domain in the list, then browser blocks the request.

To overcome this there are two ways

  1. Access-Control-Allow-Origin Response header should be set at your backend API end to allow your domain to make requests to API. Example(This example is for java component on server side. Similarly it's applicable for other server side languages as well)

Or

  1. To bypass this you have to use JSONP
Community
  • 1
  • 1
Amit.rk3
  • 2,417
  • 2
  • 10
  • 16
  • 1
    Thanks @Amit.rk3 Option number 1 worked for me. On the Backand dashboard, the backend API in this case, there is a generated signup token which is to be set in the headers and sent along with the request like so... headers: { 'SignUpToken': CONSTS.signUpToken } – Ingadi Jun 23 '16 at 17:21
  • @AxelIngadi .oh..ok.. That's great. Glad it helped – Amit.rk3 Jun 23 '16 at 17:55