ionicthemes / ionic-wordpress-integration

Ionic Wordpress starter app 😎. Learn how to communicate your ionic app with Wordpress REST API with this starter and detailed tutorial.
https://ionicthemes.com/tutorials/about/ionic-wordpress-integration
265 stars 126 forks source link

I am not able to register new user with administrator token? #20

Closed codetycon closed 5 years ago

codetycon commented 6 years ago

I am following your tutorial at https://ionicthemes.com/tutorials/about/ionic-wordpress-integration anfd I am able to login but Sigup is not working, I am using admin user to authenticate a user.

My Script looks like this

onSubmit(values){
  var username: Admin_Username;
  var password: Admin_Password;
  //only authenticated administrators can create users
  this.authenticationService.doLogin(username, password)
  .subscribe(
    res => {
      let user_data = {
        username: values.username,
        name: values.displayName,
        email: values.email,
        password: values.password
      };
      this.authenticationService.doRegister(user_data, res.json().token)
      .subscribe(
        result => {
          console.log(result);
        },
        error => {
          console.log(error);
        }
      );
    },
    err => {
      console.log(err);
    }
  )
}

Here is a Eror message:-

{
"code": "rest_cannot_create_user",
"message": "Sorry, you are not allowed to create new users.",
"data": {
"status": 401
}
}
mautematico commented 6 years ago

take the result of res.json().token and inspect it using a tool like jwt.io.

  1. Is it an actual jwt?
  2. Does it contain user creation grant?
prafullwizorbit commented 5 years ago

In wp -admin -> setting -> General please checked the checkbox for Membership anyone can register. i am attaching image

General Settings ‹ One Love Festival — WordPress if still error occurs then there must be something went wrong with jwt plugin handling.

Thanks

djabif commented 5 years ago

Thanks @prafullwizorbit for the clarification.