export default class App extends React.Component {
componentDidMount() {
firebase.auth().onAuthStateChanged(user => {
this.props.navigation.navigate(user ? 'Main' : 'Login')
})
}
这是我的App.js,我要检查用户是否经过身份验证
const firebaseConfig = {
apiKey: 'xyz',
authDomain: 'xyz',
databaseURL: 'xyz',
projectId: 'xyz',
storageBucket: 'xyz',
messagingSenderId: 'xyz'
}
firebase.initializeApp(firebaseConfig)
export default class LoginScreen extends React.Component{
state = {
email: '',
password: '',
}
handleChangeUsername = (email) => {
this.setState({email})
}
handleChangePassword = (password) => {
this.setState({password})
}
loginUser = (email, password) => {
console.log(email)
console.log(password)
try {
firebase.auth().signInWithEmailAndPassword(email, password).then(function(user) {
console.log("Success")
})
this.props.navigation.navigate("Main")
}catch(error) {
console.log(error.toString())
}
}
这是我的LoginScreen。问题是,在App.js中,它说undefined不是对象(this.props.navigation.navigate)
答案 0 :(得分:0)
这似乎是一个导航问题,如果您想检查用户是否已通过身份验证,只需注释this.props.navigation.navigate(“ Main”)并在“身份验证”选项卡上打开Firebase控制台,检查用户并查看如果您在那里有新用户。
或者您可以只使用调试器并查看身份验证的控制台日志