Last active
June 2, 2016 09:48
-
-
Save fdidron/d731008fdc62df479e77d3d007176a6f to your computer and use it in GitHub Desktop.
Fireabse - react Basic Auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Auth, DatabaseRef } from 'firebaseConfig.js'; | |
import PublicComponent from 'PublicComponent.jsx'; | |
import PrivateComponent from 'PrivateComponent.jsx'; | |
import LoadingComponent from 'LoadingComponent.jsx'; | |
class App extends React.Component { | |
constructor() { | |
this.state = { | |
auth: null | |
} | |
} | |
/* Component Custom Methods */ | |
/* End Component Custom Methods */ | |
/* React Component LifeCycle Methods */ | |
componentWillMount() { | |
Auth.onAuthStateChanged( (user) => { | |
this.setState({ | |
auth: (user) ? true : false | |
}) | |
}) | |
} | |
render() { | |
let appContent; | |
switch (this.state.auth) { | |
case true: | |
appContent = <PrivateComponent /> | |
break; | |
case false: | |
appContent = <PublicComponent />; | |
break; | |
default: | |
appContent = <LoadingComponent />; | |
break; | |
} | |
return ( | |
<div>{ appContent }</div> | |
); | |
} | |
/* End React Component LifeCycle Methods */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Firebase from 'firebase/firebase-browser'; | |
const config = { | |
apiKey: '', | |
authDomain: '', | |
databaseURL: '', | |
storageBucket: '' | |
}; | |
Firebase.initializeApp(config); | |
const DatabaseRef = Firebase.database().ref(); | |
const StorageRef = Firebase.storage().ref(); | |
const StorageImagesRef = StorageRef.child('images'); | |
const Auth = Firebase.auth(); | |
export { | |
Auth, | |
DatabaseRef, | |
StorageRef, | |
StorageImagesRef | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment