Exception 与Meteor.callLoginMethod匹配错误
我正在尝试通过以下方式发送我的登录名:Exception 与Meteor.callLoginMethod匹配错误,exception,meteor,login,Exception,Meteor,Login,我正在尝试通过以下方式发送我的登录名: 'submit form': function(event) { event.preventDefault(); event.stopPropagation(); var loginRequest = { username: event.target.loginUsername.value.toLowerCase(), password: event.target.loginPassword.value,
'submit form': function(event) {
event.preventDefault();
event.stopPropagation();
var loginRequest = {
username: event.target.loginUsername.value.toLowerCase(),
password: event.target.loginPassword.value,
};
var callback = function(response) {
Session.set('showLoading', false);
};
Session.set('showLoading', true);
Accounts.callLoginMethod({
methodArguments: [loginRequest],
userCallback: callback,
});
},
但我遇到了一个错误,我无法找出是什么原因造成了这个错误:
Exception while invoking method 'login' Error: Match error: Unknown key in field username
...
Sanitized and reported to the client as: Match failed [400]
我在网上发现了一些信息,但没有什么真正对我有帮助。我想它是在我调用Accounts.callLoginMethod时生成的
我的表单如下所示:
<form>
<div class="row">
<div class="input-field col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
<label for="loginUsername">Username</label>
<input id="loginUsername" type="text" class="form-control" disabled="{{showLoading}}" required>
<br>
<label for="loginPassword">Password</label>
<input id="loginPassword" type="password" class="form-control" disabled="{{showLoading}}" required>
</div>
</div>
<br>
{{#if showLoading}}
{{> loading}}
{{else}}
<div class="text-center">
<button type="submit" class="btn btn-primary">Login</button>
</div>
{{/if}}
</form>
用户名
密码
{{#如果显示加载}
{{>加载}
{{else}
登录
{{/if}
有人可以帮助我或者知道是什么造成了这个错误?这是我的2美分
Accounts.callLoginMethod
在技术上不是一个有文档记录的API函数,理论上可能会在未来的Meteor版本中发生变化。因为它没有文档记录,所以它返回的错误没有得到很好的定义,可能会令人困惑
由于您只是在进行密码验证,我建议您改用。至少通过这种方式,如果出现这样的错误,您可以使用一组API文档(当出现错误时,它还会返回更具体的错误)
尝试切换 并查看是否仍收到错误输出。如果是这样,错误将是下面的错误消息之一,您可以更好地调试以查看发生了什么
- “登录请求[400]的无法识别选项”,如果用户或密码未定义
- “匹配失败[400]”如果用户不是对象或字符串,或者密码不是字符串
- “找不到用户[403]”如果用户中提供的电子邮件或用户名不属于注册用户
- “密码不正确[403]”如果提供的密码不正确
- “用户未设置密码[403]”如果用户没有密码
如果遇到上述错误之一,请执行
console.log(username)
,并确保它是一个字符串或对象,具有您期望的值。再次提醒您!作为最后一次非常完整和有用的回答,谢谢!我会朝那边看的,你能帮我吗?我正在尝试使用您的解决方案转换我的上一次调用,因此我执行了Accounts.loginWithPassword(loginRequest[0],loginRequest[1],callback)
但是我遇到了一个错误Accounts.loginWithPassword()不是一个函数,尽管我进行了导入import{Meteor}从“meteor/meteor”
中,函数是meteor.loginWithPassword
而不是Accounts.loginWithPassword
。此外,您不能将loginRequest
用作数组,因为它是一个对象。改为使用loginRequest.username
和loginRequest.password
。