From 9d1f987ac1a38a6bf7a0743390dd22bdff77be33 Mon Sep 17 00:00:00 2001 From: Aditya Sankaran Date: Fri, 25 Oct 2019 13:15:17 -0400 Subject: [PATCH 1/6] added userID property for posts --- functions/handlers/post.js | 1 + 1 file changed, 1 insertion(+) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index e3d0c01..c14c61c 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -6,6 +6,7 @@ exports.putPost = (req, res) => { body: req.body.body, userHandle: req.body.userHandle, userImage: req.body.userImage, + userID: req.userData.userID, microBlogTitle: req.body.microBlogTitle, createdAt: new Date().toISOString(), likeCount: 0, From f82f9984c6fa7201f5f6628be244655f3d8e779c Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Fri, 25 Oct 2019 14:33:23 -0400 Subject: [PATCH 2/6] Comment out axios.defaults.baseUrl --- twistter-frontend/src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index db0c81c..f076cee 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -19,7 +19,7 @@ import { logoutUser, getUserData } from './redux/actions/userActions'; // Components import AuthRoute from "./util/AuthRoute"; -axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api'; +// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api'; // Pages import home from './pages/Home'; From 41bcc78c3a63edf580e19436b1c5892600d983f8 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Fri, 25 Oct 2019 15:20:10 -0400 Subject: [PATCH 3/6] Fix login page loop bug --- twistter-frontend/src/App.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index db0c81c..bec4ac6 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -19,7 +19,7 @@ import { logoutUser, getUserData } from './redux/actions/userActions'; // Components import AuthRoute from "./util/AuthRoute"; -axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api'; +// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api'; // Pages import home from './pages/Home'; @@ -36,14 +36,19 @@ const theme = createMuiTheme(themeObject); const token = localStorage.FBIdToken; if (token) { - const decodedToken = jwtDecode(token); - if (decodedToken.exp * 1000 < Date.now()) { - store.dispatch(logoutUser); + try { + const decodedToken = jwtDecode(token); + if (decodedToken.exp * 1000 < Date.now()) { + store.dispatch(logoutUser()); + window.location.href = "/login"; + } else { + store.dispatch({ type: SET_AUTHENTICATED }); + axios.defaults.headers.common['Authorization'] = token; + store.dispatch(getUserData()); + } + } catch (invalidTokenError) { + store.dispatch(logoutUser()); window.location.href = "/login"; - } else { - store.dispatch({ type: SET_AUTHENTICATED }); - axios.defaults.headers.common['Authorization'] = token; - store.dispatch(getUserData()); } } From b31a571b298f42ebdddaf79221d236912968ee22 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Fri, 25 Oct 2019 19:27:45 -0400 Subject: [PATCH 4/6] Add followedTopics array on signup --- functions/handlers/users.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 1af539d..335215a 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -77,7 +77,8 @@ exports.signup = (req, res) => { email: newUser.email, handle: newUser.handle, createdAt: newUser.createdAt, - userId + userId, + followedTopics: [] }; handle2Email.set(userCred.handle, userCred.email); return db.doc(`/users/${newUser.handle}`).set(userCred); From 981795b2880e6b98a33821ba246fb19b33a8a649 Mon Sep 17 00:00:00 2001 From: Aditya Sankaran Date: Sat, 26 Oct 2019 16:57:25 -0400 Subject: [PATCH 5/6] writing microblogs not hardcoded anymore --- functions/handlers/post.js | 4 +- functions/package-lock.json | 67 ++++++++++++++++++++- functions/package.json | 3 +- twistter-frontend/src/Writing_Microblogs.js | 3 +- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index c14c61c..f37cc62 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -4,9 +4,9 @@ exports.putPost = (req, res) => { const newPost = { body: req.body.body, - userHandle: req.body.userHandle, + userHandle: req.userData.handle, userImage: req.body.userImage, - userID: req.userData.userID, + userID: req.userData.userId, microBlogTitle: req.body.microBlogTitle, createdAt: new Date().toISOString(), likeCount: 0, diff --git a/functions/package-lock.json b/functions/package-lock.json index 439a2e2..acfe9ce 100644 --- a/functions/package-lock.json +++ b/functions/package-lock.json @@ -535,6 +535,11 @@ "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", "dev": true }, + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==" + }, "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", @@ -1190,11 +1195,18 @@ "progress": "^2.0.0", "regexpp": "^2.0.1", "semver": "^5.5.1", + "strip-ansi": "^4.0.0", "strip-json-comments": "^2.0.1", "table": "^5.2.3", "text-table": "^0.2.0" }, "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, "debug": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", @@ -1209,6 +1221,15 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", "dev": true + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "^3.0.0" + } } } }, @@ -2355,6 +2376,7 @@ "mute-stream": "0.0.7", "run-async": "^2.2.0", "rxjs": "^6.4.0", + "string-width": "^2.1.0", "strip-ansi": "^5.1.0", "through": "^2.3.6" }, @@ -2403,6 +2425,12 @@ "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", "optional": true }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, "is-obj": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", @@ -3252,7 +3280,8 @@ "dev": true, "requires": { "ansi-styles": "^3.2.0", - "astral-regex": "^1.0.0" + "astral-regex": "^1.0.0", + "is-fullwidth-code-point": "^2.0.0" } }, "snakeize": { @@ -3292,12 +3321,47 @@ "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz", "integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo=" }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "dev": true, + "requires": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "^3.0.0" + } + } + } + }, "string_decoder": { "version": "0.10.31", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", "optional": true }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "requires": { + "ansi-regex": "^4.1.0" + } + }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -3344,6 +3408,7 @@ "dev": true, "requires": { "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", "strip-ansi": "^5.1.0" } }, diff --git a/functions/package.json b/functions/package.json index 2e308b3..29b3e89 100644 --- a/functions/package.json +++ b/functions/package.json @@ -16,7 +16,8 @@ "axios": "^0.19.0", "firebase": "^6.6.2", "firebase-admin": "^8.6.0", - "firebase-functions": "^3.1.0" + "firebase-functions": "^3.1.0", + "strip-ansi": "^5.2.0" }, "devDependencies": { "eslint": "^5.12.0", diff --git a/twistter-frontend/src/Writing_Microblogs.js b/twistter-frontend/src/Writing_Microblogs.js index b1570d8..6ddb974 100644 --- a/twistter-frontend/src/Writing_Microblogs.js +++ b/twistter-frontend/src/Writing_Microblogs.js @@ -36,7 +36,6 @@ class Writing_Microblogs extends Component { // alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value); const postData = { body: this.state.value, - userHandle: "new user", userImage: "bing-url", microBlogTitle: this.state.title, microBlogTopics: this.state.topics.split(', ') @@ -46,7 +45,7 @@ class Writing_Microblogs extends Component { } axios - .post('/putPost', postData, headers) + .post("/putPost", postData, headers) .then((res) =>{ alert('Post was shared successfully!') console.log(res.data); From 19780a1395314b3d89f334da7c0cf048a5656b6c Mon Sep 17 00:00:00 2001 From: Aditya Sankaran Date: Sat, 26 Oct 2019 17:06:42 -0400 Subject: [PATCH 6/6] made userline not hardcoded --- functions/handlers/post.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index f37cc62..1db0144 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -28,7 +28,7 @@ exports.putPost = (req, res) => { }; exports.getallPostsforUser = (req, res) => { - admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get() + admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get() .then((data) => { let posts = []; data.forEach(function(doc) {