Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rakannimer/react-firebase-auth-provider

Simple authentication with React & Firebase
https://github.com/rakannimer/react-firebase-auth-provider

Last synced: 12 days ago
JSON representation

Simple authentication with React & Firebase

Awesome Lists containing this project

README

        

## Docs moved to : https://react-firebase-js.com/docs/react-firebase-auth/getting-started

## Source code moved to : https://github.com/rakannimer/react-firebase/

# React Firebase Auth

Easily integrate Firebase Authentication in your react(-native) app.

React Firebase Auth exports the following components :

- FirebaseAuthProvider
- FirebaseAuthConsumer
- IfFirebaseAuthed
- IfFirebaseAuthedAnd
- IfFirebaseUnAuthed

### Usage

Change PROJECT_NAME to your project name and grab your firebase config here :
https://console.firebase.google.com/project/PROJECT_NAME/settings/general/

```javascript
// Firebase Config
const config = {
apiKey: "API_KEY",
authDomain: "AUTH_DOMAIN",
projectId: "PROJECT_ID",

// OPTIONAL
databaseURL: "DATABASE_URL",
storageBucket: "STORAGE_BUCKET",
messagingSenderId: "MESSAGING_SENDER_ID"
};
```

Place an AuthProvider Component anywhere in your component tree as an ancestor to any of the other react-firebase-auth-provider components and pass to it your firebase config.

```javascript
import firebase from "firebase/app";
import "firebase/auth";
import {
FirebaseAuthProvider,
IfFirebaseUnAuthed,
IfFirebaseAuthed,
FirebaseAuthConsumer,
IfFirebaseAuthedAnd
} from "react-firebase-auth-provider";

const config = {
apiKey: "API_KEY",
authDomain: "AUTH_DOMAIN",
projectId: "PROJECT_ID",

// OPTIONAL
databaseURL: "DATABASE_URL",
storageBucket: "STORAGE_BUCKET",
messagingSenderId: "MESSAGING_SENDER_ID"
};

const MyApp = () => {
return (


{
const googleAuthProvider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(googleAuthProvider);
}}
>
Sign In with Google

{
firebase.auth().signInAnonymously();
}}
>
Sign In Anonymously

{
firebase.auth().signOut();
}}
>
Sign Out


{({ isSignedIn, user, providerId }) => {
return (

{JSON.stringify({ isSignedIn, user, providerId }, null, 2)}

);
}}



{() => {
return
You are authenticated
;
}}

providerId !== "anonymous"}
>
{({ providerId }) => {
return
You are authenticated with {providerId}
;
}}




);
};
```

## [Reference](https://firebase.google.com/docs/auth/)