I am working on my React Native - TypeScript app using Firebase Authentication.
On my App.tsx
file I called the following:
import {initializeApp} from 'firebase/app';import {firebaseConfig} from './config/config';export interface Props {}interface State {}export default class App extends React.Component<Props, State> { constructor(props: Props) { super(props); this.initialFirebase(); } initialFirebase = () => { initializeApp(firebaseConfig); }; render() { return <AppContainer />; }}
Then inside my LoginScreen.tsx
I called out the getAuth
method and use async to get the response from Firebase for my Signup method:
import {getAuth, createUserWithEmailAndPassword} from 'firebase/auth';export interface Props {}interface State { email: string; password: any; isLoading: boolean;}export default class LoginScreen extends React.Component<Props, State> { constructor(props: Props) { super(props); this.state = { email: '', password: '', isLoading: false, }; this.auth = getAuth(initialFirebase()); } onSignUp = async () => { if (this.state.email && this.state.password) { try { const response = await createUserWithEmailAndPassword( auth, this.state.email, this.state.password, ); } catch (error) { if (error.code == 'auth/email-already-in-use') { Alert.alert('Signup Error', 'User already exist!', [ { text: 'Ok', }, ]); } } } };
However, this returns a couple of issues:
auth
- Property 'auth' does not exist on type 'LoginScreen'.ts(2339)- Inside SignUp
auth
is not defined. error.code
returns Object is of type 'unknown' issue.
I was wondering how can I properly do this in React Native. I want to upgrade my async code but don't know how to do it. I am studying React Native and I am trying integrate Firebase on it.