0

when I try to create a new User with JavaScript and Parse in Back4App.io I receive the following error:

Unhandled Promise Rejection: SecurityError: The operation is insecure.

I use the following code:

Parse.initialize("APP_ID", "JS_KEY"); //PASTE HERE YOUR Back4App APPLICATION ID AND YOUR JavaScript KEY
Parse.serverURL = "https://parseapi.back4app.com/";

var user = new Parse.User();
user.save({
  username: 'Taki Test',
  email: 'sample@email.com',
  password: '123456'
}, {
  success: function(response) {
    alert('New object create with success! ObjectId: ' + response.id + `, ` + user.get('username'));
  },
  error: function(response, error) {
    alert('Error: ' + error.message);
  }
})
Patrick Grebe
  • 111
  • 2
  • 14

1 Answers1

0

It seems that you didn't insert your master key in your initialization code, and that was the reason you're facing this trouble.

I tested your code with master key and it worked for me.

Also, on the "API Reference" available in the Dashboard, on "User API" > Signing Up, there's a simple code that you only need to run and it will create an user too, here it is:

Parse.serverURL = 'https://parseapi.back4app.com';
Parse.initialize('appId', 'jskey', 'masterkey');

const user = new Parse.User()
user.set('username', 'A string');
user.set('email', 'email@email.com');
user.set('password', '123456');

user.signUp().then((user) => {
  if (typeof document !== 'undefined') document.write(`User signed up: ${JSON.stringify(user)}`);
  console.log('User signed up', user);
}).catch(error => {
  if (typeof document !== 'undefined') document.write(`Error while signing up user: ${JSON.stringify(error)}`);
  console.error('Error while signing up user', error);
});
Charles
  • 531
  • 2
  • 11