javascript - 如何将用户设置为登录 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 的更多信息。
推荐阅读
- python - sqlAlchemy 通过混合属性访问 blob?
- .net - 我可以将泛型方法存储在列表中吗?
- javascript - 试图将 div 从一个数组移动到另外两个数组
- xamarin - HttpClient.PostAsync 图片上传
- django - Django模型在添加之前验证ManyToMany字段
- excel - vba 运行时错误 1004 应用程序定义或对象定义错误
- java - Randoop junit 生成器为参数值填充空值
- django - 在屏幕上显示 docx 文件
- node.js - 带有CORS的Angular 5调用api
- java - 没有表单登录的spring security使用rest端点进行身份验证