Section 1
If you have reached here directly, Here is the link to the article => Connect Firebase to react project
Steps!! -
- Connect Firebase to your project.
- Add initial signup method for the new user using email and password.
- Add signup and sign-in method using Google Gmail.
- Add sign-in methods for users using email and password.
Section 2
Sign up with an Email and Password!!
Creating signups for new users is pretty simple, Firebase gives you a method createUserWithEmailAndPassword. This method helps to create a new user in the Authentication section of the Firebase console.
Before adding this method make sure you enable the Firebase email and password authentication method in the Sign-in-method tab section.


Create a user with Email + Password

Signup code



Section 3
Sign In with an Email and Password!!
Firebase provides the signInWithEmailAndPassword method, which again takes only email and password and returns the response accordingly.


Section 4
Login with Google
I will use the react-icons npm package for all sorts of icons, it's pretty simple to install plus they have a variety of icons.
I have created the Google login button.

Now, do the same step we did with email and password sign-in providers, go to the authentication sign-in method tab and enable the Google login.


Link - https://react-icons.github.io/react-iconsI have created the Google login button.Google the login Button in the login form Select an ImageNow, do the same step we did with email and password sign-in providers, go to the authentication sign-in method tab and enable the Google login.Enable Google login providers in the Firebase console Select an ImageAdd your localhost and production domain, so that Firebase can give the domain to use the above provider's permission. Select an ImageFirebase return the user data once logged in via the credentials successfully
After clicking to Google login button user will be thrown to a new tab which has the list of emails (left-hand side image), after selecting one email user will be thrown back to the main page and in the response then you will get the user data(right side image).
Google login is completed, now you can use the response data from Firebase in any way you want. I prefer to store the uid return from Firebase and token in the cookie which helps me to detect whether the user is logged in or not, if the cookie does not contain uid then the user is logged out. Also do set some expired days, for example, 14 days for every cookie value you will save in the browser.
I have added a cool loading button in every button and some covered some edge cases like clicking the button without entering an email or password and so on. It’s always a good approach to cover as many edge cases as you can, which gives the user a good user experience.
