【发布时间】:2019-07-21 20:08:38
【问题描述】:
我目前正在开发一个 React / Redux / Firebase 应用程序。
在我的 Firebase Cloud Firestore中,我存储用户数据,这些数据是在创建 Auth 用户后动态创建的。
在我的index.js 中,我使用useFirestoreForProfile: true 来获取相应的用户数据以显示在firebase.profile 中
index.js
const store = createStore(rootReducer,
compose(
applyMiddleware(
thunk.withExtraArgument({
getFirebase, // Firebase
getFirestore // Cloud Database
})
),
reduxFirestore(fbInit),
reactReduxFirebase(fbInit, {
useFirestoreForProfile: true, // Sync user data to firebase.profile
userProfile: 'users', // Tell Redux Firebase where our users are stored
attachAuthIsReady: true // Enable firebase initializing before DOM rendering
})
)
);
我的身份验证操作:
/store/actions/authActions.js
export const signIn = (credentials) => {
return (dispatch, getState, {getFirebase}) => {
const firebase = getFirebase();
firebase.auth().signInWithEmailAndPassword(
credentials.email,
credentials.password
).then(() => {
dispatch({
type: 'LOGIN_SUCCESS'
})
}).catch((err) => {
dispatch({
type: 'LOGIN_ERROR',
err
})
});
}
}
我的认证reducer中成功登录的部分:
/store/reducers/authReducer.js
case 'LOGIN_SUCCESS':
console.log('Login success');
return {
...state,
authError: null,
authErrorDetails: null
};
我将 state 映射到组件 props 的方式:
/components/pages/Dashboard/index.jsx
const mapStateToProps = (state) => {
console.log(state);
return {
records: state.firestore.ordered.records,
tabs: state.firestore.ordered.tabs,
auth: state.firebase.auth,
profile: state.firebase.profile
}
}
当前配置文件数据如下所示:
在设置这些字段的用户文档中,我创建了一个附加集合。
路径将如下所示:users -> (document id) -> tabs -> (document id) -> fields
有没有办法将标签集合包含在 firebase.profile
中最终的对象应该类似于我刚刚手动创建用于显示目的的对象:
有没有办法做到这一点?我真的希望它只是一个参数丢失或什么的。
【问题讨论】:
标签: reactjs firebase react-redux google-cloud-firestore react-redux-firebase