Skip to content

Commit

Permalink
Update the GCP and Firebase API keys
Browse files Browse the repository at this point in the history
Fetch only the pub crawls of the current user

Signed-off-by: Georgi Georgiev <[email protected]>
  • Loading branch information
ggeorgievx committed Feb 12, 2022
1 parent 02080c5 commit 8f8aeb8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
18 changes: 9 additions & 9 deletions .env
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
REACT_APP_GOOGLE_API_KEY=AIzaSyBDzQHuQl1bQkhb8ohvT3U8u4k7pfUwjV0
REACT_APP_API_KEY=AIzaSyCqubqXnU75kuNNpyVjcHM6ABKrBFAK27Y
REACT_APP_AUTH_DOMAIN=pub-crawl-267516.firebaseapp.com
REACT_APP_DATABASE_URL=https://pub-crawl-267516.firebaseio.com
REACT_APP_PROJECT_ID=pub-crawl-267516
REACT_APP_STORAGE_BUCKET=pub-crawl-267516.appspot.com
REACT_APP_MESSAGING_SENDER_ID=424140483147
REACT_APP_APP_ID=1:424140483147:web:10325db50492c6eabcbbce
REACT_APP_MEASUREMENT_ID=G-5QEW7NLPWX
REACT_APP_GOOGLE_API_KEY=AIzaSyCrSqujhDJ7B_EAKFt9xVfl4dKDZ3jspyc
REACT_APP_API_KEY=AIzaSyB2VNfDGbW644rDzfA-0JewSrmTUuGE_Eg
REACT_APP_AUTH_DOMAIN=pub-crawl-5c99f.firebaseapp.com
REACT_APP_DATABASE_URL=https://pub-crawl-5c99f-default-rtdb.firebaseio.com
REACT_APP_PROJECT_ID=pub-crawl-5c99f
REACT_APP_STORAGE_BUCKET=pub-crawl-5c99f.appspot.com
REACT_APP_MESSAGING_SENDER_ID=92532689756
REACT_APP_APP_ID=1:92532689756:web:12d436c9da821a5691cf99
REACT_APP_MEASUREMENT_ID=G-WBFTS0BNGQ
2 changes: 1 addition & 1 deletion src/axiosPubCrawls.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';

const axiosPubCrawlsInstance = axios.create({
baseURL: 'https://pub-crawl-267516.firebaseio.com/pubCrawls'
baseURL: `${process.env.REACT_APP_DATABASE_URL}/pubCrawls`
});

export default axiosPubCrawlsInstance;
31 changes: 17 additions & 14 deletions src/containers/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ const Home = () => {

return new Promise((resolve) => {
if (currentUser !== null) {
axiosPubCrawlsInstance('.json')
currentUser.getIdToken(true)
.then((idToken) => {
return axiosPubCrawlsInstance(`/${currentUser.uid}.json?auth=${idToken}`);
})
.then((response) => {
resolve(Object.keys(response.data[currentUser.uid]).length > 0);
resolve(Object.keys(response.data).length > 0);
})
.catch(() => {
resolve(false);
Expand Down Expand Up @@ -174,7 +177,7 @@ const Home = () => {
onClick={buttonHandler}
>
CONTINUE AS GUEST
</Button>
</Button>
</Tooltip>
<Tooltip
title="WITH HISTORY"
Expand All @@ -190,20 +193,20 @@ const Home = () => {
onClick={googleButtonHandler}
>
LOGIN WITH GOOGLE
</Button>
</Button>
</Tooltip>
</div>
) : (
<Button
className={classes.button}
variant="contained"
color="primary"
size="large"
onClick={buttonHandler}
>
CONTINUE
</Button>
)}
<Button
className={classes.button}
variant="contained"
color="primary"
size="large"
onClick={buttonHandler}
>
CONTINUE
</Button>
)}
</div>
<Backdrop
className={classes.backdrop}
Expand Down
15 changes: 5 additions & 10 deletions src/containers/PubCrawls/PubCrawls.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,7 @@ const PubCrawls = () => {
setBackdropOpen(true);

const normalizePubCrawls = (pubCrawls) => {
let currentUsersPubCrawls;

if (authContext.currentUser !== null) {
currentUsersPubCrawls = pubCrawls[authContext.currentUser.uid];
} else {
currentUsersPubCrawls = pubCrawls;
}
const currentUsersPubCrawls = pubCrawls;

const normalizedPubCrawls = Object.keys(currentUsersPubCrawls).map((currentUsersPubCrawlId) => {
return {
Expand All @@ -117,8 +111,9 @@ const PubCrawls = () => {
});
};

const fetchPubCrawlsFromFirebase = async () => {
const response = await axiosPubCrawlsInstance('.json');
const fetchPubCrawlsForCurrentUserFromFirebase = async (currentUser) => {
const idToken = await currentUser.getIdToken(true);
const response = await axiosPubCrawlsInstance(`/${currentUser.uid}.json?auth=${idToken}`);

normalizeAndSetPubCrawls(response.data);
};
Expand All @@ -130,7 +125,7 @@ const PubCrawls = () => {
};

if (authContext.currentUser !== null) {
fetchPubCrawlsFromFirebase();
fetchPubCrawlsForCurrentUserFromFirebase(authContext.currentUser);
} else {
retrievePubCrawlsFromLocalStorage();
}
Expand Down

0 comments on commit 8f8aeb8

Please sign in to comment.