0
我試圖根據文檔使用Firebase身份驗證偵聽器來分派logIn函數。但是我想用偵聽器觸發一個redux動作來填充我的狀態。如何使用React Native從Firebase身份驗證中分發Redux動作
當我嘗試運行下面的代碼,在與火力成功登錄時,出現「無法讀取屬性未定義‘登陸’。
請HALP
class RootApp extends Component {
componentWillMount() {
// Listen for Auth Changes
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
this.props.logIn(
uid,
displayName,
photoURL,
providerId,
email,
emailVerified
);
// User is signed in.
} else {
console.log("Not logged in");
// No user is signed in.
}
});
}
render() {
if (this.props.auth.checking == true) {
return (
<ActivityIndicator
animating={true}
style={styles.activityIndicator}
size="large"
/>
);
} else if (this.props.auth.signedIn == true) {
return <SignedIn />;
} else {
return <SignedOut />;
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
fontSize: 96
},
activityIndicator: {
flex: 1,
justifyContent: "center",
alignItems: "center",
height: 80
}
});
const mapStateToProps = state => {
return {
auth: state.auth
};
};
const mapDispatchToProps = dispatch => {
return {
logIn: (
uid,
displayName,
photoURL,
providerId,
email,
emailVerified
) => {
dispatch(
logIn(
uid,
displayName,
photoURL,
providerId,
email,
emailVerified
)
);
}
};
};
export default connect(mapStateToProps, mapDispatchToProps)(RootApp);