How to Build a Reusable React Login Component

How to Build a Reusable React Login Component

A community for learning and developing web applications using React by Facebook. Interested in building mobile apps using React Native?

Learn how to build a reusable and shareable Firebase Google login component

In this chapter, we will continue from where we left off in the first chapter that dealt with implementing a Facebook login and initiating a react app structure. We are going to add Google login to the same app we created in the first chapter. This chapter is short, sweet, and simple because we have already completed the problematic section in the previous chapter. We have broken down this tutorial into various sub-headings for you to grasp the concept about React project, Google login, firebase auth, component implementation, etc. and work accordingly.

Now, let’s get on with implementing the Google login!

What you’ll learn …?

  • How to create a new React app.
  • How to pass props in React.
  • How to use Firebase Authentication.
  • How to create and set up a Google app.
  • How to use Bit.

Most of the points have already been covered in the first chapter, so this chapter makes the concepts even clearer as we move along.

Problem

As we have done most of the problematic section in the first chapter, this chapter only tackles the issue of implementation of Google login; which is relatively simple compared to Facebook login. So, we need a quick win here without wasting much of our time. We need to generate result quickly, which is an important part that keeps us motivated to reach our end milestones.

Requirements

Here’s a complete list of plugins, packages, and services we’re going to need to gain something from this tutorial:

  • Nodejs v8.x.x or higher installed along with NPM/yarn.
  • Firebase and Bit account.
  • You’ve already completed the project from the previous chapter.
  • Firebase and Bit package.

Reusable previous code

To make things easier for us, we are going to replicate the Facebook component that we created in the first chapter and change all related names to Google. The project directory structure will look something like below:

The places where we changed the name from Facebook to Google are mentioned in detail below:

  1. Folder FacebookAuth is changed to GoogleAuth.
  2. FacebookAuth.jsx file is changed to GoogleAuth.jsx file.
  3. In GoogleAuth.jsx file, change the class name to GoogleAuth.
  4. In handleLogin() function, change the FacebookAuthProvider to GoogleAuthProvider.

Then, we need to change Facebook to Google in the HTML section as given below in the following code snippet:

<li class="firebaseui-list-item">
     <button
        onClick={this.handleLogin}
        class="firebaseui-idp-button mdl-button mdl-js-button mdl-button--raised firebaseui-idp- **google** firebaseui-id-idp-button">
         <span class="firebaseui-idp-icon-wrapper">

           <img class="firebaseui-idp-icon" alt="" src="https://www.gstatic.com/firebasejs/ui/2.0.0/images/auth/ **google**.svg">
          </span>
          <span class="firebaseui-idp-text firebaseui-idp-text-long">
              Sign in with **Google**
          </span>
          <span class="firebaseui-idp-text firebaseui-idp-text-short">
**Google**
          </span>
      </button>

The above code will provide us with the Google login component which we need to import in our App.js file.

Now, we need to copy the code below and add it to our App.js file.

In our GoogleAuth/index.js file, we need to replace all the import of FacebookAuth with GoogleAuth, as shown in the code snippet below:

Now, every change will be made only in our App.js file. We need to change the App.js file to include the component and pass firebase configuration as shown in the code snippet below:

As a result, we will see the following result in our browser screen or app screen:

We can see that this is working fine. Now, we move one to Firebase part of our tutorial chapter.

Activating the Sign-in method in Firebase

In this step, we need to activate the Sign-in method in our firebase console for Google login to work. For that, we need to:

Go to firebase console > Authentication > enable Google Sign-in Method

Lastly, we need to provide a project support email and then click on “save” button as shown in the console screenshot below:

After this is done, we need to return to our app and click on Google Login. We will see the following simulation and result in our browser console:

Finally, we have successfully implemented Google login as well in our react app.

Now, we need to push the code to Bit as in the previous chapter by creating a new collection.

Make it Reusable and Sharable with Bit

To make our code reusable and shareable, we’ll do some restructuring and move all our code to ‘components’ (this is not mandatory but a better practice, when using Bit). Then, we’ll export it (with all its dependencies), to a component collection on Bit’s cloud, to be shared with others and easily reused.

In this step, we are going to push the new component i.e. Google login component to Bit again. We already have our Bit package installed and connected to our Bit account. So, we need to create a collection and start by tracking the component.

Note: The first and second step features an installation of Bit account. These steps can be skipped if you already have a Bit account.

1. Create a collection and initialize Bit on a project

Here, we create a new collection on Bit to which we are going to push all our component code. We use the Bit “create collection” configuration page to create a new collection named “firebase-auth-collection” as shown in the screenshot below:

To successfully push the whole project to Bit, you need to follow the instructions given on the page shown below:

First, we need to install Bit CLI

Using NPM,> npm install bit-bin --global
Then, we need to go to the project directory in our Bit CLI and perform the commands bit init and run bit login on Bit CLI as shown in the screenshot below:

2. Configure a React compiler for our component

When we configure a compiler we tell Bit to capsule the component with it. Capsuling components together with their compilers gives us the freedom to use, build and test them anywhere. This includes being able to run the code in any of the applications we’d like to use the component in, as well as running it in the cloud to enable features such as the live component playground.

bit import bit.envs/compilers/react --compiler

3. Track components

We need to track our component by using the following command in your command prompt or Bit console:

bit add src/components/GoogleAuth

The result after the command is performed is shown below in the screenshot:

4. Tag and export to our collection on Bit’s cloud

Here, we are going to set a version to all tracked components, and export to this collection using following bit command:

bit tag --all 1.0.0

Finally, we need to perform following bit command to push our component code to bit collection that we created before:

bit export krissnawat.firebase-auth-collection

Now, our package is live on Bit. It is our second component in our firebase auth collection as shown in the screenshot below:

Lastly, we need to replace the component in our App.js file as shown in the code snippet below:

import React, { Component } from "react";
	// import "./App.css";
	import "./index.css";
	import FacebookAuth from "@bit/krissnawat.firebase-auth-collection.facebook-auth";
	import GoogleAuth from "./components/GoogleAuth";
	

	const firebaseConfig = {
	  apiKey: "xxxxxxxx",
	  authDomain: "xxxxxx.firebaseapp.com",
	  databaseURL: "https://xxxxxxx.firebaseio.com",
	  projectId: "xxxxxxx",
	  storageBucket: "xxxxxxx.appspot.com",
	  messagingSenderId: "xxxxxxx",
	  appId: "1:140177169073:web:xxxxxxx"
	};
	class App extends Component {
	  render() {
	    return (
	      <div className="App">
	        <FacebookAuth firebaseConfig={firebaseConfig} />
	        <GoogleAuth firebaseConfig={firebaseConfig} />
	      </div>
	    );
	  }
	}
	

	export default App;

Finally, the implementation of Google login with firebase auth and uploading the component to Bit is complete. Now, we can run the project locally to test everything.

Conclusion

In this tutorial, we learned how to implement Google login with firebase. We also learned about implementing the re-usable code in the form of components as in the previous chapter. Finally, we were successful in pushing our second component in our Firebase Auth collection.

Thanks for reading. If you liked this post, share it with all of your programming buddies!

Further reading

Understanding TypeScript

Typescript Masterclass & FREE E-Book

React - The Complete Guide (incl Hooks, React Router, Redux)

Modern React with Redux [2019 Update]

The Complete React Developer Course (w/ Hooks and Redux)

React JS Web Development - The Essentials Bootcamp

React JS, Angular & Vue JS - Quickstart & Comparison

The Complete React Js & Redux Course - Build Modern Web Apps

React JS and Redux Bootcamp - Master React Web Development

Using React-Router to Optimize Single Page Applications

Hire dedicated full-stack React native developers for custom React native application

Hire dedicated full-stack React native developers for custom React native application

The brilliant technology some of the most innovative apps like UberEars, Instagram, Airbnb is something you must have heard about. Well, React Native is the one which is the technology behind it. It has been chosen by some of the most trusted and...

The brilliant technology some of the most innovative apps like UberEars, Instagram, Airbnb is something you must have heard about. Well, React Native is the one which is the technology behind it. It has been chosen by some of the most trusted and popular brands all over the world for their mobile app development. Now, every React Native app development company providing their services to React Native development to a plethora of clients, thanks to the humungous popularity of this technology.

Hence, if you are thinking to go ahead with React Native app development, there exist few aspects to consider. For the purpose of your next mobile app development project, as well as choosing React Native development, you must know the need to hire React Native developer and how to successfully and effectively do it. However, hiring such developers for the purpose of custom React Native app development is quite a difficult job. But, let’s have a brief discussion on this highly-advanced technology.

React Native

To be clear and concise, it is essentially a JavaScript-based framework which was actually created by the social media giant, Facebook. It provides a mobile app development company with the ability to develop native apps in JavaScript. The company came up with this framework as Mark Zuckerberg, Facebook CEO, accepted that relying too much in case of mobile app development on the HTML was a mistake. They developed this framework for their app’s UI and then even went further to make it open source.

React Native applications have a modular architecture and are much more stable. It essentially allows the developer with improved coding and offers pre-loaded elements. Also, it is well-suited for the purpose of cross-platform development since it offers stability as well as budget-friendly solutions that have much better as well as optimal performance.

How to Hire Dedicated Fullstack React Native Developer

In order to hire a dedicated full-stack react native developer, you should check the following aspects and qualities in the candidate. Some of them are:

1. Comprehensive Knowledge of JavaScript with Relevant Expertise

Being an evident fact that JavaScript is the soul of React Native, it is essentially the language this technology is based on. So, React Native app developers need to have quite a comprehensive knowledge of JavaScript and relevant expertise in JavaScript in order to develop and build different components as well as an entire application. Ask questions concerning technical aspects of JavaScript, and it will help you gauge the capabilities of the developers, especially whether they are well-versed with this language or not.

2. Specific Experience in Native iOS and Android Development

Of course, there are situations where the react native developer has to work with different native tools. Hence, if he or she is familiar and in the best-case scenario, experience with native iOS and Android development, then it will certainly an additional benefit. So, hire React Native developer who actually has been involved in these developments in his or her previous projects. He should also have experience in Microsoft application development.

3. Backend Skills Expertise

In case you want to custom code the complete mobile app backend, you have to finalize a certain backend programming language at the start. This will offer you with clarity of the entire process of how to hire React Native developers. Think, you want to develop the mobile app backend using Python. So, the developer has to be knowledgeable in core Python language as well as any of its popular frameworks like Django along with development/customization of RESTful APIs, and finally, object-relational mappers (ORM) and the database with frontend skills like CSS or even HTML.

4. Impressive Debugging Skills

For every development process, there is an associated mandatory process of detection along with fixing of bugs and errors in the code. Hence, ensure that the React Native developer you hire has the inherent capability of resolving these issues.

5. Seamless Communication Skills

For a React Native developer, it is essential to have strong communication skills. A mobile app development company should go with the developer who is well-versed with the technology as well as has impressive and seamless communication skills. A developer who has impressive amazing skills easily adds more value to the mobile app development project. Also, it assists in communicating the project progress with the clients and regularly informing them about the different project development aspects.

Conclusion

Mobile apps have certainly become an essential and integral part of people’s daily lives. Hence, it has increased the demand for these apps, and mobile app development services look for frameworks that assist in the development of robust mobile apps. Pertaining to this, React Native has emerged as the best framework for not only iOS but also Android app development. React Native app development has grown proportionally higher than any other framework based development due to easier access to plugins and libraries which assist in entirely soothing and streamlining the entire mobile app development phase. However, to achieve this, a company needs to hire React Native developers who have the above-mentioned qualities and skills.

Learn React.js: Front-End Web Development for Beginners

Learn React.js: Front-End Web Development for Beginners

Learn React.js - Frontend Web Development for Beginners. In this React tutorial, you will learn the core fundamentals of React JS and Modern JavaScript so that you can start building lightning fast web apps using React JS. Learn Modern JavaScript and React JS from absolute scratch. Learn to make AJAX requests to get data from remote API and display into your web application. Learn React JS, which is one of the most exciting technology of recent time

Learn React.js - Frontend Web Development for Beginners - Web Development in 2019. In this video you will learn the core fundamentals of React JS and Modern JavaScript so that you can start building lightning fast web apps using React JS.

In this video, you will learn Modern JavaScript and React JS from absolute scratch. you will learn to make AJAX requests to get data from remote API and display into your web application.

So if you are ready to learn React JS, which is one of the most exciting technology of recent time

Thanks for watching

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Further reading

React - The Complete Guide (incl Hooks, React Router, Redux)

**☞ **Modern React with Redux [2019 Update]

**☞ **50+ Java Interview Questions for Programmers

**☞ **Top 100 Python Interview Questions and Answers

**☞ **100+ Basic Machine Learning Interview Questions and Answers

**☞ **Introduction to Java String Interview Questions and Answers

**☞ **Best 50 React Interview Questions and Answers in 2019

**☞ **Top 50+ SQL Interview Questions and Answers in 2019

**☞ **Best Java Microservices Interview Questions In 2019

**☞ **Best 50 Nodejs interview questions from Beginners to Advanced in 2019

**☞ **100+ Java Interview Questions and Answers In 2019

Top React Native Developers in the USA

For most mobile app development company it is incredibly important to maintain shorter development cycles while not compromising on feature set or cross-platform native performance. Often developers need to ensure any one if these at the expense of others. React Native is one of the development languages that ensure fast-paced development by reusing codes while boosting the apps with native capabilities.

Website: Top React Native Developers in USA