我正在使用 firebase 处理使用电子邮件和密码身份验证的身份验证,但我还想将附加用户详细信息存储到具有从电子邮件/密码身份验证生成的 uid 的集合中。
用户已注册,但其他详细信息未存储到users
集合中
包裹 -
"@firebase/app": "0.4.10",
"@firebase/auth": "0.11.4",
"@firebase/database": "0.4.7",
"@firebase/firestore": "1.4.4",
"react-redux-firebase": "2.3.0",
"redux-firestore": "0.8.0",
"redux-thunk": "2.3.0"
我正在使用 redux-thunk 异步执行用户注册,然后调度减速器。
在下面的代码中,我安慰了它们credentials
,firestore
它们分别具有值和链式方法,即使res.user.uid
存在但由于某种原因用户已注册但用户的详细信息文档未添加到users
集合中。
异步操作
export const signup = credentials => {
return (dispatch, getState, { getFirebase, getFirestore }) => {
const firebase = getFirebase();
const firestore = getFirestore();
firebase
.auth()
.createUserWithEmailAndPassword(
credentials.email,
credentials.password
)
.then(res =>
firestore
.collection("users")
.doc(res.user.uid)
.set({
name: credentials.name,
username: credentials.username
})
)
.then(() => dispatch({ type: SIGNUP_SUCCESS }))
.catch(err => dispatch({ type: SIGNUP_ERROR, err }));
};
};
store.js
import { applyMiddleware, createStore, compose } from "redux";
import thunk from "redux-thunk";
import { reduxFirestore, getFirestore } from "redux-firestore";
import { reactReduxFirebase, getFirebase } from "react-redux-firebase";
import reducers from "./reducers/index";
import firebase from "../config/firebase";
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(
reducers,
composeEnhancers(
applyMiddleware(thunk.withExtraArgument({ getFirebase, getFirestore })),
reduxFirestore(firebase),
reactReduxFirebase(firebase)
)
);
export default store;