Last active
May 31, 2020 02:02
-
-
Save jackie1santana/45241cd5510a82ffa19a5806961d1e78 to your computer and use it in GitHub Desktop.
Firebase Client or Server Side Set Up
This file contains hidden or 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
db.collection('cafes').add({ | |
name: 'jack', | |
city: 'bronx' | |
}) |
This file contains hidden or 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
//doc(id) | |
db.collection('cafes').doc('TkqHnzOVcyMsEMG7HORi').delete() |
This file contains hidden or 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
const admin = require("firebase-admin"); | |
const serviceAccount = require('./serviceAccount.json') | |
const firebase = admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount), | |
databaseURL: "https://vue-covid-19-project.firebaseio.com", | |
}); | |
const db = firebase.firestore() | |
db.collection('users').get().then((snapshot) => { | |
snapshot.docs.forEach(doc => { | |
console.log(doc.data()) | |
}) | |
}) |
This file contains hidden or 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
db.collection('cafes').get().then((snapshot) => { | |
snapshot.docs.forEach(doc => { | |
console.log(doc.data()) | |
}) | |
}) |
This file contains hidden or 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
<html> | |
<head> | |
<!-- The core Firebase JS SDK is always required and must be listed first --> | |
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-app.js"></script> | |
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-firestore.js"></script> | |
<!-- TODO: Add SDKs for Firebase products that you want to use | |
https://firebase.google.com/docs/web/setup#available-libraries --> | |
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-analytics.js"></script> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body> | |
<script> | |
// Your web app's Firebase configuration | |
var firebaseConfig = { | |
apiKey: "AIzaSyCW_F7nJQuHxSi_zditOUUg-BhGX7S1Cxs", | |
authDomain: "fire-test-5ae2d.firebaseapp.com", | |
databaseURL: "https://fire-test-5ae2d.firebaseio.com", | |
projectId: "fire-test-5ae2d", | |
storageBucket: "fire-test-5ae2d.appspot.com", | |
messagingSenderId: "230601004734", | |
appId: "1:230601004734:web:5db08659eacbc9834fb0ef", | |
measurementId: "G-0YVW4F92Y9" | |
}; | |
// Initialize Firebase | |
firebase.initializeApp(firebaseConfig); | |
firebase.analytics(); | |
const db = firebase.firestore() | |
db.settings({ timestampsInSnapshots: true}) | |
</script> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Server Side Set Up Notes
npm i firebase-admin --save
Download your credentials in firebase services account ..generate new key
rename the json file to 'serviceAccount' & store it in const serviceAccount = require('./serviceAccount.json')
place credentials in here: credential: admin.credential.cert(serviceAccount),
for deployment set environment variables for firebase config:
const firebase = admin.initializeApp({
credential: admin.credential.cert(serviceAccount,{
"private_key": process.env.FIREBASE_PRIVATE_KEY,
"client_email": process.env.FIREBASE_CLIENT_EMAIL,
}),
databaseURL: "https://devportfolio-may-2020.firebaseio.com",
});
copy the private key & client email from serviceAccount & paste them in .env
set the heroku configs
if you're using an api on the front end to the backend, use a proxy.