From 07e92711328bb3d213e805112d25e0ceb9243ba3 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Tue, 1 Oct 2019 17:30:18 -0400 Subject: [PATCH 01/11] Removing hard-coded user info. --- functions/handlers/users.js | 8 -------- functions/index.js | 33 ++++++++++++++++----------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 2a83ee7..c4ceba4 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -134,9 +134,6 @@ exports.login = (req, res) => { }; exports.getProfileInfo = (req, res) => { - // FIXME: Delete this after login is implemented - req.user = {}; - req.user.handle = 'itsjimmy'; db.collection('users').doc(req.user.handle).get() .then((data) => { @@ -149,12 +146,7 @@ exports.getProfileInfo = (req, res) => { }; exports.updateProfileInfo = (req, res) => { - // FIXME: Delete this after login is implemented - req.user = {}; - req.user.handle = 'itsjimmy'; - // TODO: Add functionality for adding/updating profile images - // Data validation const {valid, errors, profileData} = validateUpdateProfileInfo(req.body); diff --git a/functions/index.js b/functions/index.js index 04d3b4e..def41b9 100644 --- a/functions/index.js +++ b/functions/index.js @@ -1,25 +1,22 @@ /* eslint-disable promise/always-return */ const functions = require('firebase-functions'); const app = require('express')(); +const fbAuth = require('./util/fbAuth'); +const {db} = require('./util/admin'); const cors = require('cors'); app.use(cors()); -const fbAuth = require('./util/fbAuth'); - - -const {db} = require('./util/admin'); - -// const firebase = require('firebase'); -// firebase.initializeApp(config); - - - - /*------------------------------------------------------------------* * handlers/users.js * *------------------------------------------------------------------*/ -const {getUserDetails, getProfileInfo, updateProfileInfo, signup, login} = require('./handlers/users'); +const { + getUserDetails, + getProfileInfo, + login, + signup, + updateProfileInfo, +} = require('./handlers/users'); app.post('/signup', signup); @@ -28,17 +25,19 @@ app.post('/login', login); app.get('/getUser/:handle', getUserDetails); // Returns all profile data of the currently logged in user -// TODO: Add fbAuth -app.get('/getProfileInfo', getProfileInfo); +app.get('/getProfileInfo', fbAuth, getProfileInfo); // Updates the currently logged in user's profile information -// TODO: Add fbAuth -app.post('/updateProfileInfo', updateProfileInfo); +app.post('/updateProfileInfo', fbAuth, updateProfileInfo); + /*------------------------------------------------------------------* * handlers/post.js * *------------------------------------------------------------------*/ -const {putPost, getallPostsforUser} = require('./handlers/post'); +const { + getallPostsforUser, + putPost, +} = require('./handlers/post'); app.get('/getallPostsforUser', getallPostsforUser); From 9d4f175a49bd82f8aa9cc49ab07f028280078a0b Mon Sep 17 00:00:00 2001 From: Aditya Sankaran Date: Tue, 1 Oct 2019 19:07:57 -0400 Subject: [PATCH 02/11] added entering topics field and database call for adding topics when writing microblog --- functions/handlers/post.js | 1 + functions/index.js | 3 ++- twistter-frontend/src/Userline.js | 9 ++++++-- twistter-frontend/src/Writing_Microblogs.js | 25 ++++++++++++++++----- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index d15ea33..20528c0 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -11,6 +11,7 @@ exports.putPost = (req, res) => { createdAt: new Date().toISOString(), likeCount: 0, commentCount: 0, + microBlogTopics: req.body.microBlogTopics }; diff --git a/functions/index.js b/functions/index.js index 6ff3bd3..05f3dd3 100644 --- a/functions/index.js +++ b/functions/index.js @@ -253,7 +253,8 @@ const {putPost, getallPostsforUser} = require('./handlers/post'); app.get('/getallPostsforUser', getallPostsforUser); // Adds one post to the database -app.post('/putPost', fbAuth, putPost); +app.post('/putPost', firebaseAuth, putPost); + exports.api = functions.https.onRequest(app); \ No newline at end of file diff --git a/twistter-frontend/src/Userline.js b/twistter-frontend/src/Userline.js index 51d74f4..e8168ce 100644 --- a/twistter-frontend/src/Userline.js +++ b/twistter-frontend/src/Userline.js @@ -9,7 +9,8 @@ class Userline extends Component { { super(props); this.state = { - microBlogs : [] + microBlogs : [], + } } @@ -21,12 +22,16 @@ class Userline extends Component { const post = res.data; this.setState({microBlogs : post}) - }) + }) + + } render() { + let sortedPosts = []; + return (