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
| // Dependencies | |
| const admin = require('firebase-admin'); | |
| const express = require('express'); | |
| // Setup | |
| const db = admin.database(); | |
| const router = express.Router(); | |
| // Middleware | |
| router.use(bodyParser.json()); |
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 db = admin.database(); | |
| const express = require('express'); | |
| const router = express.Router(); |
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 db = admin.database(); | |
| const express = require('express'); | |
| const router = express.Router(); | |
| router.get('/words', async (req, res) => { | |
| try { | |
| const wordsSnapshot = await db.ref('words/').once('value'); | |
| if (wordsSnapshot.val()) { |
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
| fetch('https://example.com/api/v1/example-resource') | |
| .then( response => { | |
| // data retrived | |
| // log success | |
| }) | |
| .catch( error => { | |
| // handle error | |
| }); |
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 express = require('express'); | |
| const helmet = require('helmet'); | |
| const app = express(); | |
| app.use(helmet()); |
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 express = require('express'); | |
| const router = express.Router(); | |
| router.get('/', (req, res) => { | |
| const {limit} = req.query; | |
| } |
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 authObserver = firebase.auth().onAuthStateChanged( user => { | |
| if (user) { | |
| // Handle user data | |
| // Unsubscribe from observer | |
| authObserver(); | |
| } | |
| }); |
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
| firebase.auth().onAuthStateChanged( user => { | |
| if (user) { | |
| // If user state changes and 'user' exists, check Firebase Database for user | |
| const userReference = db.ref(`users/${user.uid}`); | |
| userReference.once('value', snapshot => { | |
| if (!snapshot.val()) { | |
| // User does not exist, create user entry | |
| userReference.set({ | |
| email: user.email, | |
| displayName: user.displayName |
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 wordsReference = firebase.database().ref(`words/${uid}`); | |
| wordsReference.once('value', snapshot => { | |
| // Callback only runs once | |
| }); |
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 wordsReference = firebase.database().ref(`words/${uid}`); | |
| wordsReference.on('value', snapshot => { | |
| // Callback runs whenever data changes | |
| }); |