Issues with Wildcard and particle-api-js

Dear community.

I have tried to learn particle-api-js and been trying some login examples i have found, example

particle.login({username: 'email', password: 'password'})
  .then(
    function(data){
      access_token = data.body.access_token;
    },
    function(err) {
      console.log('API call completed on promise fail: ', err);
    }
  );

But when i try it chrome console returns this error

XMLHttpRequest cannot load https://api.particle.io/oauth/token.
A wildcard ‘*’ cannot be used in the 'Access-Control-Allow-Origin’
header when the credentials flag is true. Origin 'http://localhost:3000
is therefore not allowed access. The credentials mode of an
XMLHttpRequest is controlled by the withCredentials attribute.

I have been googling around about this error and what i can find is that

“this is a part of security, you cannot do that. If you want to allow credentials then your Access-Control-Allow-Origin must not use *. You will have to specify the exact domain.”

But as a beginner i just cant find where i need to do this.
I also can see on this forum that several people have this issues so not sure if this is something that has started because of an update?

Can someone please explain where i need to specify the domain or/else remove the wildcard for a beginner?

BR
Dimi

It’d help if you could post the complete code, that’d save us from guessing what you’re doing?

Hello Moors.

I am sorry. I have used example code

var Particle = require('particle-api-js');

var particle = new Particle();
var access_token = "";

//get access token
particle.login({username: 'email', password: 'password'})
  .then(
    function(data){
      access_token = data.body.access_token;
    },
    function(err) {
      console.log('API call completed on promise fail: ', err);
    }
  );

var pumpStuff = function(message){
  var fnPr = particle.callFunction({
      deviceId: 'jackdaniels',
      name: 'leanMachine',
      argument: message,
      auth: access_token
    });

  fnPr.then(
    function(data) {u
      console.log('Function called succesfully:', data);
    }, function(err) {
      console.log('An error occurred:', err);
    }
  );
};

exports.pumpStuff = pumpStuff;

But i cant pass the login part.

I use Meteor as framework but there is nothing in the HTML part and the app seems to work fine except that in the backgound chrome shows the error message.

<body>
  <div class="container">
    <header>
      <h1>Todo List</h1>
    </header>
  </div>
</body>

I have tried several other particle-api-js examples i have found but they all act the same.
another example is


 if (Meteor.isServer) {
    var Particle = Meteor.npmRequire('particle-api-js');
    var particle = new Particle();

    var particleLogin = particle.login({
        username: 'USERNAME',
        password: 'PASSWORD'
    });

    particleLogin.then(function (data) {
        return data.body.access_token;
    }).then(function (token) {
        console.log(token);
        return particle.getEventStream({
            deviceId: 'DEVICE_ID',
            auth: token
        });
    }).then(function (stream) {
        stream.on('event', function (data) {
            var eventString = data.name + ": " + data.data;
            console.log(eventString);
        });
    });
}

If you need something else please let me know.

BR
Dimi

I have been struggling some more about this today and read some threads on various places.
I could see that the particle-api-js was updated on version 5.2.3 in regards to the user-agent issue so i thought something happened there.

Later on i read a part about meteors way of handling server side code so i was thinking that maybe the
code needs to be on the server side now. i tested the login example code on
https://docs.particle.io/reference/javascript/ and put it on serverside
and the server consol log gave me back a success login when i used my login
so i guess it works.

Could it be that everyone that have posted issues about this use meteor?
if someone could confirm this it would be nice.

BR
Dimi