diff --git a/src/index.js b/src/index.js
index 9e85ad1..fe50810 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,8 +6,9 @@ import * as serviceWorker from "./serviceWorker";
import { Auth0Provider } from "./utils/auth0-spa";
import history from "./utils/history";
import config from "./utils/auth_config.json"; // for safety reasons this file is not tracked by git
+import Firebase, { FirebaseContext } from "./services/Firebase";
-const onRedirectCallBack = appState => {
+const onRedirectCallBack = (appState) => {
history.push(
appState && appState.targetUrl
? appState.targetUrl
@@ -22,7 +23,9 @@ ReactDOM.render(
redirect_uri={window.location.origin}
onRedirectCallBack={onRedirectCallBack}
>
-
+
+
+
,
document.getElementById("root")
);
diff --git a/src/services/Firebase/context.js b/src/services/Firebase/context.js
new file mode 100644
index 0000000..9ecd255
--- /dev/null
+++ b/src/services/Firebase/context.js
@@ -0,0 +1,5 @@
+import { createContext, useContext } from "react";
+
+const FirebaseContext = createContext(null);
+export const useFirebase = () => useContext(FirebaseContext);
+export default FirebaseContext;
diff --git a/src/services/Firebase/firebase.js b/src/services/Firebase/firebase.js
new file mode 100644
index 0000000..6adcf4e
--- /dev/null
+++ b/src/services/Firebase/firebase.js
@@ -0,0 +1,40 @@
+import app from "firebase/app";
+import "firebase/firestore";
+import config from "./config.json";
+
+const CONFIG = {
+ apiKey: config.apiKey,
+ authDomain: config.authDomain,
+ databaseURL: config.databaseURL,
+ projectId: config.projectId,
+ storageBucket: config.storageBucket,
+ messagingSenderId: config.messagingSenderId,
+ appId: config.appId,
+ measurementId: config.measurementId,
+};
+
+export default class Firebase {
+ constructor() {
+ app.initializeApp(CONFIG);
+ this.db = app.firestore();
+ }
+
+ add = async (email, id, fav) => {
+ await this.db
+ .collection("MealPlannerFavs")
+ .add({ email: email, idMeal: id, isfav: fav })
+ .then((ref) => {
+ console.log("Added document with ID: ", ref.id);
+ })
+ .catch((error) => console.error("Error adding document: ", error));
+ };
+
+ getByEmail = async (email) => {
+ const query = await this.db
+ .collection("MealPlannerFavs")
+ .where("email", "==", email)
+ .get();
+ const snapshot = query.docs[0];
+ return snapshot.data();
+ };
+}
diff --git a/src/services/Firebase/index.js b/src/services/Firebase/index.js
new file mode 100644
index 0000000..35e5c18
--- /dev/null
+++ b/src/services/Firebase/index.js
@@ -0,0 +1,5 @@
+import Firebase from "./firebase";
+import FirebaseContext, { useFirebase } from "./context";
+
+export default Firebase;
+export { FirebaseContext, useFirebase };
diff --git a/src/utils/auth_config.json b/src/utils/auth_config.json
deleted file mode 100644
index 334dd30..0000000
--- a/src/utils/auth_config.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "domain": "chefs-meal-planner.eu.auth0.com",
- "clientId": "EXe8HCfFd0jSSfqzjAvpdk72ce0y2Hh9"
-}
\ No newline at end of file