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 provider = new firebase.auth.GoogleAuthProvider(); | |
| firebase.auth().signInWithPopup(provider).then(function(result) { | |
| const user = result.user; | |
| }); |
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.database.ref(`users/${userId}`).set({ | |
| user, | |
| email, | |
| profile_picture: imageUrl | |
| }); |
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 starCountRef = firebase.database().ref(`posts/${postId}/${starCount}`); | |
| starCountRef.on('value', snapshot => { | |
| updateStarCount(postElement, snapshot.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
| const wordsReference = firebase.database().ref(`words/${uid}`); | |
| wordsReference.on('value', snapshot => { | |
| // Callback runs whenever data changes | |
| }); |
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
| 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 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
| 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 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
| fetch('https://example.com/api/v1/example-resource') | |
| .then( response => { | |
| // data retrived | |
| // log success | |
| }) | |
| .catch( error => { | |
| // handle error | |
| }); |
OlderNewer