Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Updating Firebase SDK V8 to V9 in React Native and Typescript

$
0
0

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:

  1. auth - Property 'auth' does not exist on type 'LoginScreen'.ts(2339)
  2. Inside SignUp auth is not defined.
  3. 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.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>