Skip to content

Firebase Authentication(Facebook, Google, Email) for React app

Notifications You must be signed in to change notification settings

serikshaikamalov/firebase-auth-setup

Repository files navigation

Sign-in with Firebase Authentication

You can use this library to easily integrate with Firebase Authorization for your React app.

Screenshot 2023-07-07 at 17 26 55

Installation

npm i firebase-auth-setup

How to use

PS: Before starting please prepare the config file that you can find on your Firebase account page. Copy the content of the firebase config and put it inside .env.local file(first you will be needed to rename the .env.local-sample file to .env.local)

  1. Wrap your app component with FirebaseContext.Provider and pass firebase global object with firebaseConfig. In index.js
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import {
  FirebaseContext,
  FirebaseStore,
} from "firebase-auth-setup/dist/firebase-setups";

import firebaseConfig from "./firebase-config";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <FirebaseContext.Provider value={new FirebaseStore(firebaseConfig)}>
    <App />
  </FirebaseContext.Provider>
);
  1. Import social media buttons from firebase-auth-setup/dist/components
import {
  GoogleLoginButton,
  FacebookLoginButton,
} from "firebase-auth-setup/dist/components";

Use them on your react component:

<GoogleLoginButton
    title="Login with Google"
    onSuccess={onSuccessLogin}
    onFailure={onLoginFailure}
/>
<FacebookLoginButton
    title="Login with Facebook"
    onSuccess={onSuccessLogin}
    onFailure={onLoginFailure}
/>

You can easily predefine props by passing title, onSuccess and onFailure handler. All props are OPTIONAL
Here:
title - the label of a button
onSuccess - your custom function that will be fired after logging in
onFailure - your custom function which will be fired when something happens during sig-in process\

Demo

We already prepared a demo. Just clone the repo and run:

npm install
npm run start

Where can you reach me?

To stay connected follow me on Github: Serik

About

Firebase Authentication(Facebook, Google, Email) for React app

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published