Skip to content

Commit

Permalink
init firebase in the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleh Lutsenko committed May 6, 2019
1 parent 1cdf5c7 commit 19c9915
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "exopen-c2af4"
}
}
6 changes: 6 additions & 0 deletions database.rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rules": {
".read": true,
".write": true
}
}
19 changes: 19 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
11 changes: 11 additions & 0 deletions src/firebase/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

const FirebaseContext = React.createContext(null);

export const withFirebase = Component => props => (
<FirebaseContext.Consumer>
{ firebase => <Component {...props} firebase={firebase} />}
</FirebaseContext.Consumer>
);

export default FirebaseContext;
35 changes: 35 additions & 0 deletions src/firebase/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import app from 'firebase/app';
import 'firebase/database';

const config = {
apiKey: "AIzaSyCvwmNhhs-1PEF9Qk1gOYNpp-m65-0JJNY",
authDomain: "exopen-c2af4.firebaseapp.com",
databaseURL: "https://exopen-c2af4.firebaseio.com",
projectId: "exopen-c2af4",
storageBucket: "exopen-c2af4.appspot.com",
messagingSenderId: "1003479661787"
};

class Firebase {
constructor() {
app.initializeApp(config);

this.db = app.database();
this.auth = app.auth();
}

// *** Auth API ***
createUserWithEmailAndPassword = (email, password) =>
this.auth.createUserWithEmailAndPassword(email, password);

signInWithEmailAndPassword = (email, password) =>
this.auth.signInWithEmailAndPassword(email, password);

signOut = () => this.auth.signOut();

sendPasswordResetEmail = email => this.auth.sendPasswordResetEmail(email);

updatePassword = password => this.auth.currentUser.updatePassword(password);
}

export default Firebase;
6 changes: 6 additions & 0 deletions src/firebase/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Firebase from './firebase';
import FirebaseContext from './context';

export default Firebase;

export { FirebaseContext };
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './components/App';
import * as serviceWorker from './serviceWorker';
// import * as serviceWorker from './serviceWorker';
import Firebase, { FirebaseContext } from './firebase';

ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(
<FirebaseContext.Provider value={new Firebase()}>
<App />
</FirebaseContext.Provider>,
document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
// serviceWorker.unregister();

0 comments on commit 19c9915

Please sign in to comment.