firebase-auth-setup
v0.1.26
Published
You can use this library to easily integrate with Firebase Authorization for your React app.
Downloads
5
Readme
Sign-in with Firebase Authentication
You can use this library to easily integrate with Firebase Authorization for your React app.
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)
- 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>
);
- 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