我寫了我的自定義方法登錄,但我在最後一步被阻止:客戶端的有效登錄。流星 - 成功登錄服務器端後返回客戶端
我相信我正確地記錄在服務器端,但沒有客戶端:
- 我在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