我写了我的自定义方法登录,但我在最后一步被阻止:客户端的有效登录。流星 - 成功登录服务器端后返回客户端
我相信我正确地记录在服务器端,但没有客户端:
- 我在DB得到了充分&正确(时间戳相干)
LoginTokens
(when
&hashedToken
)。 - 在minimongo,我有机会获得所有文件,至少我是店主(
this.userId
)。 - 允许登录尝试
Accounts.validateLoginAttempt(function (attempt)
,包含正确的用户并且不返回任何错误。 - 在客户机上通话的回归,
Meteor.loggingIn()
是false
和Meteor.user()
是null
- 在服务器
Accounts.onLogin(function(user)
返回细末user._id
所以我想这是对返回给客户端(如用户的问题。 _id) - 但我迷路了,认为我需要一位经验丰富的批评家的眼睛。
PS:我有[email protected] & [email protected]
登录方法(从客户端通常称为)
Meteor.methods({
logTwo (userfinal, passfinal) {
// Consistency var check
check(userfinal, String);
const passwordValidator = {digest: String, algorithm: String};
check(passfinal, passwordValidator);
// check user
const getUser = Accounts.findUserByEmail(userfinal);
if (!getUser) {throw invalidLogin();}
// check password
const checkPassword = Accounts._checkPassword(getUser, passfinal);
if (checkPassword.error) {throw invalidLogin();}
// get user's id
var userID = getUser._id
// logic here
console.log('code verified'); // rightly printed
// below, I tried with or without methodArguments (this, 'login', {user: userfinal,password: passfinal},
// and (this, 'login', '',
Accounts._attemptLogin(this, 'login', {user: userfinal,password: passfinal}, {
type: '2FALogin',
userId: userID,
});
},
});
Accounts.validateLoginAttempt(function (attempt) {
console.log(attempt); // rightly printed
if (attempt.type === '2FALogin' && attempt.methodName === 'login') {
console.log('allowed'); // rightly printed
return true;
}
if (attempt.error) {
console.log('login error: ' + attempt.error);
}
});
回报Accounts.validateLoginAttempt的(函数(企图)(console.log(企图))
{ type: '2FALogin',
allowed: true,
methodName: 'login',
methodArguments:
[ '[email protected]',
{ digest: '70bd58ff28477...', // digest here ok
algorithm: 'sha-256' } ],
user:
{ _id: '6i6vLjc8Ssg6SGJNf',
createdAt: 2017-11-01T15:08:52.332Z,
services: { password: [Object], resume: [Object] },
emails: [ [Object], [Object] ],
_loggedIn: true,
},
connection:
{ id: 'xFLv3XZWztxsdxckM',
close: [Function: close],
onClose: [Function: onClose],
clientAddress: '127.0.0.1',
httpHeaders:
{ 'x-forwarded-for': '127.0.0.1',
'x-forwarded-proto': 'ws',
host: 'localhost:3000',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36',
'accept-language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,la;q=0.6' } } }
您是否尝试过的方法调用'Meteor.loginWithPassword'当一切都已经验证?在方法中也可能值得尝试'this.setUserId'? –
我想这只是一个计时问题。我想,在你的方法回调被调用的时候,用户文档还没有发布到客户端,因此尚不可用。 – MasterAM
@MasterAM如何解决它? – Ontokrat