Authentication In React Native Using Firebase

suggest change

Replace the placeholder strings with your app's Firebase values. email and password are the credentials you collected. onLoginSuccess and onLoginFail are methods on this component. Call initializeApp once, outside the component. Calling it on every mount throws because the app already exists.

import React, { Component } from 'react';
import firebase from 'firebase';

firebase.initializeApp({
  apiKey: "yourAPIKey",
  authDomain: "authDomainName",
  databaseURL: "yourDomainBaseURL",
  projectId: "yourProjectID",
  storageBucket: "storageBucketValue",
  messagingSenderId: "senderIdValue"
});

export default class Login extends Component {
  componentWillMount() {
    firebase.auth().signInWithEmailAndPassword(email, password)
      .then(this.onLoginSuccess)
      .catch(() => {
        firebase.auth().createUserWithEmailAndPassword(email, password)
          .then(this.onLoginSuccess)
          .catch(this.onLoginFail);
      });
  }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents