【发布时间】:2019-03-25 07:30:12
【问题描述】:
我正在使用 Firebase 通过 Facebook 或 google 处理我的身份验证。我真正不明白的是我的商店没有更新的原因。
下面是我的代码示例:
import { createStore } from 'redux';
import {app, facebookProvider, googleProvider } from './../config/config';
const initialState = {
SCREEN_CURRENT: "login",
authenticated: false
}
const reducer = (state = initialState, action) => {
console.log('reducer', action);
switch(action.type){
case "AUTH_LOGIN_FACEBOOK":
state = {
...state,
authenticated: true
}
app.auth().signInWithPopup(facebookProvider)
.then((user, error) => {
if(error){
console.log("Unable to login with Facebook!");
} else {
console.log("Logged in succesfully");
state = Object.assign({}, state, {
authenticated: true
});
}
}).catch((error) => {
if(error){
console.log("Error from Facebook: " + error.message);
}
});
break;
case "AUTH_LOGIN_GOOGLE":
app.auth().signInWithPopup(googleProvider)
.then((user, error) => {
if(error){
console.log("Unable to login with Google!");
} else {
console.log("Logged in succesfully");
return Object.assign({}, state, {
authenticated: true
});
}
}).catch((error) => {
if(error){
console.log("Error from Google: " + error.message);
}
});
break;
default:
break;
}
return state;
}
const store = createStore(reducer);
store.subscribe(() => {
console.log("Store updated", store.getState());
});
export default store;
有人可以解释为什么我的商店没有更新,即使我在成功登录时将身份验证状态更改为 true(发生了这种情况)?
我不明白为什么。
当我单击触发“AUTH_LOGIN_FACEBOOK”操作的按钮时,商店会更新。但是,不是当我将身份验证的状态更改为 true 时。如何让商店更新?
【问题讨论】:
标签: reactjs facebook firebase react-redux