服务器端帐户创建错误
Server side account creation error
我一直在尝试让创建的服务器端帐户用户正常工作,但我在使用服务器端的 check() 方法时遇到了问题。 (我为此使用简单模式)
当密码为空时,这会导致 check() 抛出错误,这是正确的。但是,这是一个服务器端错误,我不太确定如何将其传播到客户端以进行捕获和处理。
我在浏览器控制台看到的异常如下:
Exception while simulating the effect of invoking 'createUserAccount' Meteor.makeErrorType.errorClass {message: "Match error: One or more properties do not match the schema.", path: "", sanitizedError: Meteor.makeErrorType.errorClass, errorType: "Match.Error", stack: (...)…} Error: Match error: One or more properties do not match the schema.
at SimpleSchema.condition (http://localhost:3000/packages/aldeed_simple-schema.js?8fda161c43c0ba62801a10b0dfcc3eab75c6db88:2450:11)
at checkSubtree (http://localhost:3000/packages/check.js?ac81167b8513b85b926c167bba423981b0c4cf9c:255:17)
at check (http://localhost:3000/packages/check.js?ac81167b8513b85b926c167bba423981b0c4cf9c:67:5)
at Meteor.methods.createUserAccount (http://localhost:3000/both/methods/accounts.js?c418120e76666f0ca774a281caafc39bc2c3a59d:4:27)
at http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4244:25
at _.extend.withValue (http://localhost:3000/packages/meteor.js?81e2f06cff198adaa81b3bc09fc4f3728b7370ec:949:17)
at _.extend.apply (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4235:54)
at _.extend.call (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4113:17)
at Object.Template.PasswordRegister.events.submit form (http://localhost:3000/client/views/shared/accounts/accounts.js?ac573d92938a2b3d6107ea19e50065f7ac5d41b3:36:20)
at null. (http://localhost:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:3147:18)
这是我的客户端代码的样子:
Template.PasswordRegister.events({
'submit form': function(event, template) {
event.preventDefault();
var user = {
email: template.find('#email').value,
password: template.find('#password').value
};
Meteor.call('createUserAccount', user, function(error) {
if (error) {
console.log("CONSOLE : " + error);
//TODO DO SOMETHING
// return alert(error.reason);
} else {
Meteor.loginWithPassword(user.email, user.password, function(error) {
if (error) {
console.log("CONSOLE : " + error);
//TODO DO SOMETHING
// return alert(error.reason);
}
});
}
});
}
});
这是我的服务器端代码:
Meteor.methods({
createUserAccount: function(user) {
// Important server-side check for security and data integrity
check(user, Schema.registration);
var email = user.email;
var password = user.password;
this.unblock();
return Accounts.createUser({
email: email,
password: password
});
}
});
我试过用普通的 try catch 块包装客户端代码,但没有任何区别;控制台错误仍然显示。
如错误消息所述,您在客户端上定义了 'createUserAccount' 的方法存根。是客户端存根抛出异常。
包装 if (Meteor.isServer)
显示的方法,使其远离客户端上的 运行。
if (Meteor.isServer ){
Meteor.methods({
createUserAccount: function (user) { ... }
});
}
如果这不起作用,请在您的项目中搜索定义方法存根的客户端代码。
为了弄清楚发生了什么,我已经 a meteorpad 使用一种在客户端上错误存根的方法,该方法会抛出您在浏览器控制台中看到的错误。然后我添加了第二种方法,'creatUserAccount1',它只在服务器上定义。当调用第二个方法时,它的错误由回调处理,不会导致异常。我认为这就是您想要的行为。
我一直在尝试让创建的服务器端帐户用户正常工作,但我在使用服务器端的 check() 方法时遇到了问题。 (我为此使用简单模式)
当密码为空时,这会导致 check() 抛出错误,这是正确的。但是,这是一个服务器端错误,我不太确定如何将其传播到客户端以进行捕获和处理。
我在浏览器控制台看到的异常如下:
Exception while simulating the effect of invoking 'createUserAccount' Meteor.makeErrorType.errorClass {message: "Match error: One or more properties do not match the schema.", path: "", sanitizedError: Meteor.makeErrorType.errorClass, errorType: "Match.Error", stack: (...)…} Error: Match error: One or more properties do not match the schema.
at SimpleSchema.condition (http://localhost:3000/packages/aldeed_simple-schema.js?8fda161c43c0ba62801a10b0dfcc3eab75c6db88:2450:11)
at checkSubtree (http://localhost:3000/packages/check.js?ac81167b8513b85b926c167bba423981b0c4cf9c:255:17)
at check (http://localhost:3000/packages/check.js?ac81167b8513b85b926c167bba423981b0c4cf9c:67:5)
at Meteor.methods.createUserAccount (http://localhost:3000/both/methods/accounts.js?c418120e76666f0ca774a281caafc39bc2c3a59d:4:27)
at http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4244:25
at _.extend.withValue (http://localhost:3000/packages/meteor.js?81e2f06cff198adaa81b3bc09fc4f3728b7370ec:949:17)
at _.extend.apply (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4235:54)
at _.extend.call (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4113:17)
at Object.Template.PasswordRegister.events.submit form (http://localhost:3000/client/views/shared/accounts/accounts.js?ac573d92938a2b3d6107ea19e50065f7ac5d41b3:36:20)
at null. (http://localhost:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:3147:18)
这是我的客户端代码的样子:
Template.PasswordRegister.events({
'submit form': function(event, template) {
event.preventDefault();
var user = {
email: template.find('#email').value,
password: template.find('#password').value
};
Meteor.call('createUserAccount', user, function(error) {
if (error) {
console.log("CONSOLE : " + error);
//TODO DO SOMETHING
// return alert(error.reason);
} else {
Meteor.loginWithPassword(user.email, user.password, function(error) {
if (error) {
console.log("CONSOLE : " + error);
//TODO DO SOMETHING
// return alert(error.reason);
}
});
}
});
}
});
这是我的服务器端代码:
Meteor.methods({
createUserAccount: function(user) {
// Important server-side check for security and data integrity
check(user, Schema.registration);
var email = user.email;
var password = user.password;
this.unblock();
return Accounts.createUser({
email: email,
password: password
});
}
});
我试过用普通的 try catch 块包装客户端代码,但没有任何区别;控制台错误仍然显示。
如错误消息所述,您在客户端上定义了 'createUserAccount' 的方法存根。是客户端存根抛出异常。
包装 if (Meteor.isServer)
显示的方法,使其远离客户端上的 运行。
if (Meteor.isServer ){
Meteor.methods({
createUserAccount: function (user) { ... }
});
}
如果这不起作用,请在您的项目中搜索定义方法存根的客户端代码。
为了弄清楚发生了什么,我已经 a meteorpad 使用一种在客户端上错误存根的方法,该方法会抛出您在浏览器控制台中看到的错误。然后我添加了第二种方法,'creatUserAccount1',它只在服务器上定义。当调用第二个方法时,它的错误由回调处理,不会导致异常。我认为这就是您想要的行为。