![](/img/trans.png)
[英]firebase.auth().signInWithPhoneNumber + express on Node.js
[英]How to set the user as logged in on firebase.auth(node.js)?
我有一個使用自定義令牌登錄的應用程序,寫在webpack上觀察到。 我現在想做的是通過自定義令牌成功登錄后將用戶標記為登錄到Firebase auth和Firebase Firestore上,在那里我擁有用戶的集合,並為每個用戶提供帶有數據和一些uid的文檔。 我不知道該怎么做。
這是我的代碼:
generateToken(uid) {
const uid = 'some-uid';
this.trigger(this.signals.action.onGenerateToken);
firebase.admin.auth().createCustomToken(uid)
.then((customToken) => {
console.log(customToken);
})
.catch(function (error){
if (error.Code === 'auth/invalid-custom-token') {
alert('The token you provided is not valid.');
}
else {
this.trigger(this.signals.error.onGenerateToken);
}
})
}
login(uid) {
firebase.auth().signInWithCustomToken(token)
.then(function() {
var user = firebase.auth().currentUser;
if (user) {
//mark the user as active (logged) after successful login on firebase auth and firebase firestore
};
this.trigger(this.signals.success.onLogin);
})
.catch(function(error) {
if (errorCode === 'auth/too-many-requests') {
this.trigger(this.signals.error.tooManyRequests);
}
else {
this.trigger(this.signals.error.userDisabled);
}
});
}
如果我正確理解了您的問題,請首先創建對您的用戶文檔的引用,然后在該引用上調用update()
並傳遞一個包含要更新的屬性及其新值的對象。
let userRef = firebase.database().ref('users/' + userId);
userRef.update({active:true});
查看firebase文檔 ,以獲取有關如何讀寫firebase的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.