Это мой App.js
import { View } from 'react-native';
import firebase from '@firebase/app';
import { Header } from './components/common';
import LoginForm from './components/LoginForm';
type Props = {};
export default class App extends Component<Props> {
componentWillMount() {
firebase.initializeApp({
apiKey: 'AIzaSyAq4eGitgRxVzu2CTRLtTygGflOb99CM0Q',
authDomain: 'auth-62da8.firebaseapp.com',
databaseURL: 'https://auth-62da8.firebaseio.com',
projectId: 'auth-62da8',
storageBucket: 'auth-62da8.appspot.com',
messagingSenderId: '851651021407'
});
}
render() {
return (
<View>
<Header headerText='Authentication' />
<LoginForm />
</View>
);
}
}
Это мой LoginForm.js
import React, { Component } from 'react';
import { Text } from 'react-native';
import firebase from '@firebase/app';
import { Button, Card, CardSection, Field, Spinner } from './common';
require('@firebase/auth');
class LoginForm extends Component {
state = { email: '', password: '', error: '', loading: false };
onButtonPress() {
this.setState({ error: '', loading: true });
firebase.auth().signInWithEmailAndPassword(this.state.email, this.state.password)
.then(this.onLoginSuccess.bind(this))
.catch(() => {
firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
.then(this.onLoginSuccess.bind(this))
.catch(this.onLoginFail.bind(this));
});
}
onLoginFail() {
this.setState({
loading: false,
error: 'Authentication Failed'
});
}
onLoginSuccess() {
this.setState({
email: '',
password: '',
loading: false,
error: ''
});
}
renderButton() {
if (this.state.loading) {
return <Spinner size='small' />;
}
return (
<Button onPress={this.onButtonPress.bind(this)}>
Login
</Button>
);
}
render() {
return (
<Card>
<CardSection>
<Field
labelText={'Email'}
placeholder={'email'}
value={this.state.email}
onChangeText={email => this.setState({ email })}
/>
</CardSection>
<CardSection>
<Field
labelText={'Password'}
placeholder={'password'}
hideInput
value={this.state.password}
onChangeText={password => this.setState({ password })}
/>
</CardSection>
<Text style={styles.errorTextStyle}>
{this.state.error}
</Text>
<CardSection>
{this.renderButton()}
</CardSection>
</Card>
);
}
}
const styles = {
errorTextStyle: {
fontSize: 20,
alignSelf: 'center',
color: 'red'
}
};
export default LoginForm;
У меня была та же проблема, что и у вас, и это импорт / требует исправленияЭто.Надеюсь, это поможет!