【发布时间】:2021-09-10 07:42:07
【问题描述】:
我正在使用 Firebase.auth() 对 Google Firebase 的登录进行身份验证,然后我检索 UID 并将其发送到我的 Redux Store。除非我导航到下一页然后返回登录页面,否则 UID 不会发送到商店。看来我的操作顺序已关闭,如何在我的 Redux 商店中获取 UID 而无需重新登录/刷新页面。
class Home extends React.Component {
constructor(props) {
super(props);
this.state = {
id: ''
}
}
id (value) {
this.props.id(value);
}
handleLogin = (load) => {
const { email, password } = this.state
Firebase.auth()
.signInWithEmailAndPassword(email, password)
.then(async cred => {
return db.collection('users').doc(cred.user.uid).set({
test: 'test'
})
})
.then(() => this.props.navigation.navigate('AddProfiles'))
.catch(error => console.log(error))
const currentUser = firebase.auth().currentUser;
const userId = currentUser["uid"];
this.setState({
id: userId
})
this.props.id(this.state.id);
}
<TouchableOpacity style={styles.signupbutton}>
<Button
color='white'
title="Log in"
onPress={(payload) => this.handleLogin()}
/>
</TouchableOpacity>
const mapStateToProps = (state) => {
return {
counter: state.counter,
value: state.id
};
}
const mapDispatchToProps = dispatch => {
return {
id: (value) => dispatch({ type: 'id', payload: value })
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Home)
【问题讨论】:
标签: javascript react-native redux google-cloud-firestore firebase-authentication