javascript - 如何将令牌和用户身份验证存储在 firestore ..?
问题描述
我想将用户的令牌和电子邮件、密码存储在 firestore。如果我将代码放入 js 文件并登录,就会创建 firestore 集合……对吧?
但是我可以从控制台获取一些消息……而不是 Firestore 数据。
在我的控制台中......有消息,1.“获得许可”2.解释我的服务人员 3.“令牌”
这是我的代码的一部分。firebase.init.js
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
const loginUser = ({
email,
password
}) => {
return (dispatch) => {
// dispatch action
dispatch({
type: LOGIN_USER
})
.catch(function(error) {
console.log('error occured.')
});
auth.createUserWithEmailAndPassword(email, password) **changed
.then((userCredential) => {
// Signed in
var user = userCredential.user;
// ...
})
.catch((error1) => {
var errorCode = error1.code;
var errorMessage = error1.message;
console.log(errorCode, errorMessage);
// ..
});
};
};
messaging.requestPermission()
.then(function() {
console.log('got the permission');
// get the device's push token
return messaging.getToken()
})
.then(function(token) {
const { currentUser } = auth();
token => {
console.log(currentUser.email, currentUser.uid)
.catch(function(error2) {
console.log('error2 occured.')
});
// store token in the user's document
db.collection('users').doc(currentUser.uid)
.set({
pushToken: token,
numFinds: 0,
numCares: 0
})
.catch(function(error3) {
console.log('error3 occured.' );
});
};
console.log(token);
})
.catch(function(error4) {
console.log('error4 occured.');
});
谢谢你的帮助。
解决方案
我的理解是您没有正确使用该功能createUserWithEmailAndPassword
,请抓住该功能的错误,因为它可能会揭示问题。
来自 [1]
firebase.auth().createUserWithEmailAndPassword(email, password)
.then((userCredential) => {
// Signed in
var user = userCredential.user;
// ...
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
// ..
});
[1] https://firebase.google.com/docs/auth/web/password-auth#create_a_password-based_account
推荐阅读
- javascript - 添加 - 在 ReactJS 中的字符串中
- android - 颤振警报应用程序,仅通过 java 和 Objective-C 代码安排警报?
- node.js - 如何在一个redis上保存2个数据?
- python - 使用 BFS 的二叉树的最大深度 - 为什么深度是预期的两倍?
- apache-spark - 强制写入空 Parquet 分区
- node.js - 将 HTTP 基本身份验证添加到服务器上通配符域中的静态页面的方法是什么?
- sql - Redshift 查询输出对于 RAM 来说太大
- r - 如何识别数据框中的特定字符串并将新列分配给特定值?
- react-native - 还有其他 react-native-webview 替代方案吗?
- javascript - 使用 Angular 表填充数组数据的数组?