编程语言
首页 > 编程语言> > javascript-错误解析SDK:无法使用空名称注册用户

javascript-错误解析SDK:无法使用空名称注册用户

作者:互联网

我正在尝试使用Parse SDK注册用户.我的密钥是正确的,我使用了自己的代码以及直接从Parse Quickstart Tutorial开始的“ Signing Up”代码,但我不断收到此错误消息:

Cannot sign up user with an empty name.

我什至将值硬编码到signUp函数中,并将值(和typeof)打印到控制台以提高准确性,但还是不走运.这是我创建的函数的一个片段,几乎完全是本教程的内容.

var newUserEmail    = document.getElementById("new-user-email").value;
var newUserPassword = document.getElementById("new-user-password").value;
var user = new Parse.User();
user.set("email", newUserEmail);
user.set("password", newUserPassword);
user.set("name", "no name");
user.signUp(null, {
    success: function(user) {
        console.log("New user signed up successfully!");
    },
    error: function(user, error) {
        console.log("You messed up. Error: " + error.message);
    }
});

解决方法:

您应该设置用户名:

user.set("username", "my name");

您从Parse Quickstart Tutorial中提到:

If a signup isn’t successful, you should read the error object that is returned. The most likely case is that the username or email has already been taken by another user. You should clearly communicate this to your users, and ask them try a different username.

You are free to use an email address as the username. Simply ask your users to enter their email, but fill it in the username property — Parse.User will work as normal. We’ll go over how this is handled in the reset password section.

标签:parse-platform,rest,javascript
来源: https://codeday.me/bug/20191121/2052360.html