From d2032eef75147002c58f9ffbb4e2549f694c0efb Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sun, 20 Oct 2019 21:45:24 -0400 Subject: [PATCH 01/19] Login with username works now --- functions/handlers/users.js | 11 ++ functions/package-lock.json | 232 +++++--------------------- twistter-frontend/README.md | 5 + twistter-frontend/package.json | 2 +- twistter-frontend/src/pages/Login.js | 2 +- twistter-frontend/src/pages/Signup.js | 2 +- 6 files changed, 58 insertions(+), 196 deletions(-) diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 00d8f1c..d0f4c57 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -1,4 +1,5 @@ /* eslint-disable promise/catch-or-return */ + const { admin, db } = require("../util/admin"); const config = require("../util/config"); const { validateUpdateProfileInfo } = require("../util/validator"); @@ -6,6 +7,9 @@ const { validateUpdateProfileInfo } = require("../util/validator"); const firebase = require("firebase"); firebase.initializeApp(config); +var handle2Email = new Map(); +handle2Email.set("DancingDon", "don@email.com"); + exports.signup = (req, res) => { const newUser = { email: req.body.email, @@ -76,6 +80,7 @@ exports.signup = (req, res) => { createdAt: newUser.createdAt, userId }; + handle2Email.set(userCred.handle, userCred.email); return db.doc(`/users/${newUser.handle}`).set(userCred); }) .then(() => { @@ -93,16 +98,22 @@ exports.signup = (req, res) => { exports.login = (req, res) => { const user = { email: req.body.email, + handle: req.body.handle, password: req.body.password }; // Auth validation let errors = {}; + const emailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + // Email check if (user.email.trim() === "") { errors.email = "Email must not be blank."; } + else if (!user.email.match(emailRegEx)) { + user.email = handle2Email.get(user.email); + } // Password check if (user.password.trim() === "") { diff --git a/functions/package-lock.json b/functions/package-lock.json index a20f589..439a2e2 100644 --- a/functions/package-lock.json +++ b/functions/package-lock.json @@ -34,21 +34,6 @@ "dom-storage": "2.1.0", "tslib": "1.10.0", "xmlhttprequest": "1.8.0" - }, - "dependencies": { - "@firebase/logger": { - "version": "0.1.25", - "resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz", - "integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w==" - }, - "@firebase/util": { - "version": "0.2.28", - "resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz", - "integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==", - "requires": { - "tslib": "1.10.0" - } - } } }, "@firebase/app-types": { @@ -70,15 +55,9 @@ "integrity": "sha512-foQHhvyB0RR+mb/+wmHXd/VOU+D8fruFEW1k79Q9wzyTPpovMBa1Mcns5fwEWBhUfi8bmoEtaGB8RSAHnTFzTg==" }, "@firebase/database": { -<<<<<<< HEAD - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.3.tgz", - "integrity": "sha512-LnXKRE1AmjlS+iRF7j8vx+Ni8x85CmLP5u5Pw5rDKhKLn2eTR1tJKD937mUeeGEtDHwR1rrrkLYOqRR2cSG3hQ==", -======= "version": "0.5.4", "resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.4.tgz", "integrity": "sha512-Hz1Bi3fzIcNNocE4EhvvwoEQGurG2BGssWD3/6a2bzty+K1e57SLea2Ied8QYNBUU1zt/4McHfa3Y71EQIyn/w==", ->>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f "requires": { "@firebase/database-types": "0.4.3", "@firebase/logger": "0.1.25", @@ -113,11 +92,7 @@ "@firebase/firestore": { "version": "1.5.3", "resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-1.5.3.tgz", -<<<<<<< HEAD - "integrity": "sha512-CPYLvkGZBKE47oQC9a0q13UMVRj3LvnSbB1nOerktE3CGRHKy44LxDumamN8Kj067hV/80mKK9FdbeUufwO/Rg==", -======= "integrity": "sha512-O/yAbXpitOA6g627cUl0/FHYlkTy1EiEKMKOlnlMOJF2fH+nLVZREXjsrCC7N2tIvTn7yYwfpZ4zpSNvrhwiTA==", ->>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f "requires": { "@firebase/firestore-types": "1.5.0", "@firebase/logger": "0.1.25", @@ -126,21 +101,6 @@ "@grpc/proto-loader": "^0.5.0", "grpc": "1.23.3", "tslib": "1.10.0" - }, - "dependencies": { - "@firebase/logger": { - "version": "0.1.25", - "resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz", - "integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w==" - }, - "@firebase/util": { - "version": "0.2.28", - "resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz", - "integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==", - "requires": { - "tslib": "1.10.0" - } - } } }, "@firebase/firestore-types": { @@ -173,16 +133,6 @@ "@firebase/util": "0.2.28", "idb": "3.0.2", "tslib": "1.10.0" - }, - "dependencies": { - "@firebase/util": { - "version": "0.2.28", - "resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz", - "integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==", - "requires": { - "tslib": "1.10.0" - } - } } }, "@firebase/installations-types": { @@ -190,6 +140,11 @@ "resolved": "https://registry.npmjs.org/@firebase/installations-types/-/installations-types-0.1.2.tgz", "integrity": "sha512-fQaWIW8hyX1XUN7+FCSPjvM1agFjGidVuF4Sxi7aFwfyh5t+4fD2VpM4wCQbWmodnx4fZLvsuQd9mkxxU+lGYQ==" }, + "@firebase/logger": { + "version": "0.1.25", + "resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz", + "integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w==" + }, "@firebase/messaging": { "version": "0.4.11", "resolved": "https://registry.npmjs.org/@firebase/messaging/-/messaging-0.4.11.tgz", @@ -198,16 +153,6 @@ "@firebase/messaging-types": "0.3.2", "@firebase/util": "0.2.28", "tslib": "1.10.0" - }, - "dependencies": { - "@firebase/util": { - "version": "0.2.28", - "resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz", - "integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==", - "requires": { - "tslib": "1.10.0" - } - } } }, "@firebase/messaging-types": { @@ -225,21 +170,6 @@ "@firebase/performance-types": "0.0.3", "@firebase/util": "0.2.28", "tslib": "1.10.0" - }, - "dependencies": { - "@firebase/logger": { - "version": "0.1.25", - "resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz", - "integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w==" - }, - "@firebase/util": { - "version": "0.2.28", - "resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz", - "integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==", - "requires": { - "tslib": "1.10.0" - } - } } }, "@firebase/performance-types": { @@ -272,16 +202,6 @@ "@firebase/storage-types": "0.3.3", "@firebase/util": "0.2.28", "tslib": "1.10.0" - }, - "dependencies": { - "@firebase/util": { - "version": "0.2.28", - "resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz", - "integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==", - "requires": { - "tslib": "1.10.0" - } - } } }, "@firebase/storage-types": { @@ -289,6 +209,14 @@ "resolved": "https://registry.npmjs.org/@firebase/storage-types/-/storage-types-0.3.3.tgz", "integrity": "sha512-fUp4kpbxwDiWs/aIBJqBvXgFHZvgoND2JA0gJYSEsXtWtVwfgzY/710plErgZDeQKopX5eOR1sHskZkQUy0U6w==" }, + "@firebase/util": { + "version": "0.2.28", + "resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz", + "integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==", + "requires": { + "tslib": "1.10.0" + } + }, "@firebase/webchannel-wrapper": { "version": "0.2.26", "resolved": "https://registry.npmjs.org/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.2.26.tgz", @@ -607,12 +535,6 @@ "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", "dev": true }, - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true - }, "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", @@ -830,28 +752,28 @@ "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "requires": { "number-is-nan": "^1.0.0" + } + }, + "string-width": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "^2.0.0" + } + } } }, - "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" - } - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "requires": { - "ansi-regex": "^2.0.0" - } - } - } -}, "code-point-at": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", @@ -1190,15 +1112,9 @@ } }, "end-of-stream": { -<<<<<<< HEAD - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", - "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", -======= "version": "1.4.3", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.3.tgz", "integrity": "sha512-cbNhPFS6MlYlWTGncSiDYbdqKhwWFy7kNeb1YSOG6K65i/wPTkLVCJQj0hXA4j0m5Da+hBWnqopEnu1FFelisQ==", ->>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f "optional": true, "requires": { "once": "^1.4.0" @@ -1274,7 +1190,6 @@ "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" @@ -1556,33 +1471,6 @@ "@firebase/polyfill": "0.3.22", "@firebase/storage": "0.3.12", "@firebase/util": "0.2.28" - }, - "dependencies": { - "@firebase/database": { - "version": "0.5.4", - "resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.4.tgz", - "integrity": "sha512-Hz1Bi3fzIcNNocE4EhvvwoEQGurG2BGssWD3/6a2bzty+K1e57SLea2Ied8QYNBUU1zt/4McHfa3Y71EQIyn/w==", - "requires": { - "@firebase/database-types": "0.4.3", - "@firebase/logger": "0.1.25", - "@firebase/util": "0.2.28", - "faye-websocket": "0.11.3", - "tslib": "1.10.0" - } - }, - "@firebase/logger": { - "version": "0.1.25", - "resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz", - "integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w==" - }, - "@firebase/util": { - "version": "0.2.28", - "resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz", - "integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==", - "requires": { - "tslib": "1.10.0" - } - } } }, "firebase-admin": { @@ -1710,8 +1598,7 @@ "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", - "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", - "optional": true + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=" }, "gaxios": { "version": "2.0.1", @@ -2259,15 +2146,9 @@ } }, "gtoken": { -<<<<<<< HEAD - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-4.0.0.tgz", - "integrity": "sha512-XaRCfHJxhj06LmnWNBzVTAr85NfAErq0W1oabkdqwbq3uL/QTB1kyvGog361Uu2FMG/8e3115sIy/97Rnd4GjQ==", -======= "version": "4.1.0", "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-4.1.0.tgz", "integrity": "sha512-wqyn2gf5buzEZN4QNmmiiW2i2JkEdZnL7Z/9p44RtZqgt4077m4khRgAYNuu8cBwHWCc6MsP6eDUn/KkF6jFIw==", ->>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f "optional": true, "requires": { "gaxios": "^2.0.0", @@ -2441,8 +2322,7 @@ "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", - "optional": true + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=" }, "inflight": { "version": "1.0.6", @@ -2457,8 +2337,7 @@ "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "optional": true + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "inquirer": { "version": "6.5.2", @@ -2476,7 +2355,6 @@ "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" }, @@ -2525,14 +2403,6 @@ "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-754xOG8DGn8NZDr4L95QxFfvAMs=", - "requires": { - "number-is-nan": "^1.0.0" - } - }, "is-obj": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", @@ -2929,7 +2799,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "optional": true, "requires": { "wrappy": "1" } @@ -3374,8 +3243,7 @@ "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", - "optional": true + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" }, "slice-ansi": { "version": "2.1.0", @@ -3384,8 +3252,7 @@ "dev": true, "requires": { "ansi-styles": "^3.2.0", - "astral-regex": "^1.0.0", - "is-fullwidth-code-point": "^2.0.0" + "astral-regex": "^1.0.0" } }, "snakeize": { @@ -3425,31 +3292,12 @@ "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": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.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": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "^3.0.0" - } - }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -3496,7 +3344,6 @@ "dev": true, "requires": { "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", "strip-ansi": "^5.1.0" } }, @@ -3755,8 +3602,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "optional": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write": { "version": "1.0.3", diff --git a/twistter-frontend/README.md b/twistter-frontend/README.md index f41c183..e4bc8be 100644 --- a/twistter-frontend/README.md +++ b/twistter-frontend/README.md @@ -1,5 +1,10 @@ This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). + +Cloud: https://us-central1-twistter-e4649.cloudfunctions.net/api +Local: http://localhost:5001/twistter-e4649/us-central1/api (npm install --save firebase) + + Below you will find some information on how to perform common tasks.
You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md). diff --git a/twistter-frontend/package.json b/twistter-frontend/package.json index f03c528..9289adf 100644 --- a/twistter-frontend/package.json +++ b/twistter-frontend/package.json @@ -39,5 +39,5 @@ "last 1 safari version" ] }, - "proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api" + "proxy": "http://localhost:5001/twistter-e4649/us-central1/api" } diff --git a/twistter-frontend/src/pages/Login.js b/twistter-frontend/src/pages/Login.js index 7e3be76..ef7e5c4 100644 --- a/twistter-frontend/src/pages/Login.js +++ b/twistter-frontend/src/pages/Login.js @@ -146,7 +146,7 @@ export class Login extends Component { )} {errors.general && ( - Wrong Email or Password + Invalid username/email or password )} diff --git a/twistter-frontend/src/pages/Signup.js b/twistter-frontend/src/pages/Signup.js index d4b9c3c..91e4e52 100644 --- a/twistter-frontend/src/pages/Signup.js +++ b/twistter-frontend/src/pages/Signup.js @@ -159,7 +159,7 @@ export class Signup extends Component { )} {errors.general && ( - Wrong Email or Password + Invalid username/email or password )} From cb4885cadf1a12cd04715ec80b9da89441d77ffc Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sun, 20 Oct 2019 21:49:21 -0400 Subject: [PATCH 02/19] Switched proxy back to cloud --- twistter-frontend/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twistter-frontend/package.json b/twistter-frontend/package.json index 9289adf..f03c528 100644 --- a/twistter-frontend/package.json +++ b/twistter-frontend/package.json @@ -39,5 +39,5 @@ "last 1 safari version" ] }, - "proxy": "http://localhost:5001/twistter-e4649/us-central1/api" + "proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api" } From bb0343ab30fc52d10221645542fb8a6daebc942b Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Tue, 22 Oct 2019 15:08:07 -0400 Subject: [PATCH 03/19] Remove redundant profile --- twistter-frontend/src/components/profile/StaticProfile.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 twistter-frontend/src/components/profile/StaticProfile.js diff --git a/twistter-frontend/src/components/profile/StaticProfile.js b/twistter-frontend/src/components/profile/StaticProfile.js deleted file mode 100644 index e69de29..0000000 From dede04aa8ec9e2ec1f6cc0c65e3ac2e607be5a97 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Tue, 22 Oct 2019 15:08:38 -0400 Subject: [PATCH 04/19] added dependency --- package-lock.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package-lock.json b/package-lock.json index c7bbe95..61107d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -204,6 +204,11 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz", "integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA==" }, + "jwt-decode": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", + "integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk=" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", From 1b66f18dd50245723382445a4a104283f7668eb3 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Tue, 22 Oct 2019 16:50:38 -0400 Subject: [PATCH 05/19] Log in with username partially works --- functions/handlers/users.js | 56 +++++++++++++++++++++++++++++++++++-- functions/index.js | 4 +++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/functions/handlers/users.js b/functions/handlers/users.js index d0f4c57..bf372df 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -8,7 +8,6 @@ const firebase = require("firebase"); firebase.initializeApp(config); var handle2Email = new Map(); -handle2Email.set("DancingDon", "don@email.com"); exports.signup = (req, res) => { const newUser = { @@ -75,7 +74,7 @@ exports.signup = (req, res) => { .then((idToken) => { token = idToken; const userCred = { - email: req.body.email, + email: newUser.email, handle: newUser.handle, createdAt: newUser.createdAt, userId @@ -145,6 +144,59 @@ exports.login = (req, res) => { }); }; +//Deletes user account +exports.deleteUser = (req, res) => { + //var user = firebase.auth().currentUser; + //var user = admin.auth().getUserByEmail(req.body.email); + + /*firebase.auth().onAuthStateChanged(function(user) { + console.log("user"); + console.log(user.email); + console.log("user"); + if (user) { + user.delete() + .then(function() { + console.log("User successfully deleted!"); + res.status(200).send("Deleted user."); + return; + }) + .catch(function(error) { + console.log("Error deleting user.", err); + res.status(500).send("Failed to delete user."); + }); + } else { + console.log("Cannot get user"); + res.status(500).send("Cannot get user"); + } + });*/ + + /*admin.auth().getUserByEmail(req.body.email) + .then(userRecord => { + const uid = userRecord.uid; + return admin.auth().deleteUser(uid); + }) + .then(() => { + console.log("User successfully deleted!"); + res.status(200).send("Deleted user."); + return; + }) + .catch(err => { + console.log("Error deleting user.", err); + res.status(500).send("Failed to delete user."); + });*/ + + /*user.delete() + .then(function() { + console.log("User successfully deleted!"); + res.status(200).send("Deleted user."); + return; + }) + .catch(function(error) { + console.log("Error deleting user.", err); + res.status(500).send("Failed to delete user."); + });*/ +}; + // Returns all data in the database for the user who is currently signed in exports.getProfileInfo = (req, res) => { db.collection("users") diff --git a/functions/index.js b/functions/index.js index 5c728bc..41a126c 100644 --- a/functions/index.js +++ b/functions/index.js @@ -15,6 +15,7 @@ const { getProfileInfo, login, signup, + deleteUser, updateProfileInfo } = require("./handlers/users"); @@ -27,6 +28,9 @@ app.post("/signup", signup); // and password app.post("/login", login); +//Deletes user account +app.delete("/delete", deleteUser); + app.get("/getUser/:handle", getUserDetails); // Returns all profile data of the currently logged in user From e984afff74a20e78076ccb0f799ac1fc2bebfa20 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Tue, 22 Oct 2019 18:26:21 -0400 Subject: [PATCH 06/19] modified profile.js --- twistter-frontend/src/components/profile/Profile.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 twistter-frontend/src/components/profile/Profile.js diff --git a/twistter-frontend/src/components/profile/Profile.js b/twistter-frontend/src/components/profile/Profile.js new file mode 100644 index 0000000..f87513f --- /dev/null +++ b/twistter-frontend/src/components/profile/Profile.js @@ -0,0 +1,11 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import { connect } from 'react-redux'; +import { mergeClasses } from '@material-ui/styles'; + +class Profile extends Component { + render(); + + return +} \ No newline at end of file From bc0b2549b4a28f949595078e13c1cf9364366f0a Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Tue, 22 Oct 2019 20:45:48 -0400 Subject: [PATCH 07/19] Delete user backend code works --- functions/handlers/users.js | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/functions/handlers/users.js b/functions/handlers/users.js index bf372df..4371148 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -146,15 +146,12 @@ exports.login = (req, res) => { //Deletes user account exports.deleteUser = (req, res) => { - //var user = firebase.auth().currentUser; - //var user = admin.auth().getUserByEmail(req.body.email); + var currentUser; - /*firebase.auth().onAuthStateChanged(function(user) { - console.log("user"); - console.log(user.email); - console.log("user"); - if (user) { - user.delete() + firebase.auth().onAuthStateChanged(function(user) { + currentUser = user; + if (currentUser) { + currentUser.delete() .then(function() { console.log("User successfully deleted!"); res.status(200).send("Deleted user."); @@ -168,6 +165,19 @@ exports.deleteUser = (req, res) => { console.log("Cannot get user"); res.status(500).send("Cannot get user"); } + }); + + //var user = firebase.auth().currentUser; + + /*user.delete() + .then(function() { + console.log("User successfully deleted!"); + res.status(200).send("Deleted user."); + return; + }) + .catch(function(error) { + console.log("Error deleting user.", err); + res.status(500).send("Failed to delete user."); });*/ /*admin.auth().getUserByEmail(req.body.email) @@ -184,17 +194,6 @@ exports.deleteUser = (req, res) => { console.log("Error deleting user.", err); res.status(500).send("Failed to delete user."); });*/ - - /*user.delete() - .then(function() { - console.log("User successfully deleted!"); - res.status(200).send("Deleted user."); - return; - }) - .catch(function(error) { - console.log("Error deleting user.", err); - res.status(500).send("Failed to delete user."); - });*/ }; // Returns all data in the database for the user who is currently signed in From ad853923c8c2d47e58b0cd2faa3cfaba5a7bf6f7 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Wed, 23 Oct 2019 17:18:52 -0400 Subject: [PATCH 08/19] Delete Account on UI can log the user out --- functions/handlers/users.js | 28 ---------- twistter-frontend/src/App.js | 2 + .../src/components/layout/NavBar.js | 9 ++- twistter-frontend/src/pages/Delete.js | 56 +++++++++++++++++++ .../src/redux/actions/userActions.js | 6 ++ 5 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 twistter-frontend/src/pages/Delete.js diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 4371148..7f5a39a 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -166,34 +166,6 @@ exports.deleteUser = (req, res) => { res.status(500).send("Cannot get user"); } }); - - //var user = firebase.auth().currentUser; - - /*user.delete() - .then(function() { - console.log("User successfully deleted!"); - res.status(200).send("Deleted user."); - return; - }) - .catch(function(error) { - console.log("Error deleting user.", err); - res.status(500).send("Failed to delete user."); - });*/ - - /*admin.auth().getUserByEmail(req.body.email) - .then(userRecord => { - const uid = userRecord.uid; - return admin.auth().deleteUser(uid); - }) - .then(() => { - console.log("User successfully deleted!"); - res.status(200).send("Deleted user."); - return; - }) - .catch(err => { - console.log("Error deleting user.", err); - res.status(500).send("Failed to delete user."); - });*/ }; // Returns all data in the database for the user who is currently signed in diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index b4b1aec..b767156 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -25,6 +25,7 @@ import signup from './pages/Signup'; import login from './pages/Login'; import user from './pages/user'; import logout from './pages/Logout'; +import Delete from './pages/Delete'; import writeMicroblog from './Writing_Microblogs.js'; import editProfile from './pages/editProfile'; import userLine from './Userline.js'; @@ -61,6 +62,7 @@ class App extends Component { + diff --git a/twistter-frontend/src/components/layout/NavBar.js b/twistter-frontend/src/components/layout/NavBar.js index 92ad833..5f8d28d 100644 --- a/twistter-frontend/src/components/layout/NavBar.js +++ b/twistter-frontend/src/components/layout/NavBar.js @@ -50,9 +50,12 @@ import withStyles from "@material-ui/core/styles/withStyles"; - + + ) diff --git a/twistter-frontend/src/pages/Delete.js b/twistter-frontend/src/pages/Delete.js new file mode 100644 index 0000000..22f1682 --- /dev/null +++ b/twistter-frontend/src/pages/Delete.js @@ -0,0 +1,56 @@ +/* eslint-disable */ +import React, { Component } from "react"; +import PropTypes from "prop-types"; + +// Material UI stuff +import Button from "@material-ui/core/Button"; +import withStyles from "@material-ui/core/styles/withStyles"; + +// Redux stuff +import { deleteUser } from "../redux/actions/userActions"; +import { connect } from "react-redux"; + +const styles = { + form: { + textAlign: "center" + }, + textField: { + marginBottom: 30 + }, + pageTitle: { + marginBottom: 40 + }, + button: { + positon: "relative", + marginBottom: 30 + }, + progress: { + position: "absolute" + } +}; + +export class Delete extends Component { + + componentDidMount() { + this.props.deleteUser(); + this.props.history.push('/'); + } + + render() { + return null; + } +} + +const mapStateToProps = (state) => ({ + user: state.user +}); + +const mapActionsToProps = { deleteUser }; + +Delete.propTypes = { + deleteUser: PropTypes.func.isRequired, + user: PropTypes.object.isRequired, + classes: PropTypes.object.isRequired +}; + +export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Delete)); diff --git a/twistter-frontend/src/redux/actions/userActions.js b/twistter-frontend/src/redux/actions/userActions.js index 9b9b9a1..f6cd7f9 100644 --- a/twistter-frontend/src/redux/actions/userActions.js +++ b/twistter-frontend/src/redux/actions/userActions.js @@ -61,6 +61,12 @@ export const logoutUser = () => (dispatch) => { dispatch({ type: SET_UNAUTHENTICATED }); } +export const deleteUser = () => (dispatch) => { + localStorage.removeItem('FBIdToken'); + delete axios.defaults.headers.common['Authorization']; + dispatch({ type: SET_UNAUTHENTICATED }); +} + const setAuthorizationHeader = (token) => { const FBIdToken = `Bearer ${token}`; localStorage.setItem('FBIdToken', FBIdToken); From 45f88861c8bae1501d2a7965c33f3653316c45f8 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Wed, 23 Oct 2019 18:08:42 -0400 Subject: [PATCH 09/19] Delete Account works on the UI now --- twistter-frontend/src/redux/actions/userActions.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/twistter-frontend/src/redux/actions/userActions.js b/twistter-frontend/src/redux/actions/userActions.js index f6cd7f9..5993804 100644 --- a/twistter-frontend/src/redux/actions/userActions.js +++ b/twistter-frontend/src/redux/actions/userActions.js @@ -62,6 +62,20 @@ export const logoutUser = () => (dispatch) => { } export const deleteUser = () => (dispatch) => { + axios + .delete("/delete") + .then((res) => { + console.log(res); + console.log("User account successfully deleted."); + } + ) + .catch((err) => { + dispatch ({ + type: SET_ERRORS, + payload: err.response.data, + }) + }); + localStorage.removeItem('FBIdToken'); delete axios.defaults.headers.common['Authorization']; dispatch({ type: SET_UNAUTHENTICATED }); From b17fb1f3f0da536f8d58b46897f6de09f216b46e Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Wed, 23 Oct 2019 23:16:43 -0400 Subject: [PATCH 10/19] Update fbAuth so the user data from firebase is stored in req.userData --- functions/util/fbAuth.js | 1 + 1 file changed, 1 insertion(+) diff --git a/functions/util/fbAuth.js b/functions/util/fbAuth.js index 3b59d14..35253e7 100644 --- a/functions/util/fbAuth.js +++ b/functions/util/fbAuth.js @@ -32,6 +32,7 @@ module.exports = (req, res, next) => { .then((data) => { req.user.handle = data.docs[0].data().handle; // Save username req.user.imageUrl = data.docs[0].data().imageUrl; + req.userData = data.docs[0].data(); // Stores all user data from the database return next(); }) .catch((err) => { From eea2f56b490c1ab8f6016d023087a15f92b65866 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Thu, 24 Oct 2019 15:27:20 -0400 Subject: [PATCH 11/19] Code for removing user from db still in progress (commented out) --- functions/handlers/post.js | 43 +++++++++++++-------------- functions/handlers/users.js | 24 +++++++++++---- twistter-frontend/src/pages/Delete.js | 8 ++--- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 5f361fe..e3d0c01 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -15,29 +15,28 @@ exports.putPost = (req, res) => { }; admin.firestore().collection('posts').add(newPost) - .then((doc) => { - const resPost = newPost; - resPost.postId = doc.id; - return res.status(200).json(resPost); - }) - .catch((err) => { - console.error(err); - return res.status(500).json({ error: 'something is wrong'}); - }); + .then((doc) => { + const resPost = newPost; + resPost.postId = doc.id; + return res.status(200).json(resPost); + }) + .catch((err) => { + console.error(err); + return res.status(500).json({ error: 'something is wrong'}); + }); }; exports.getallPostsforUser = (req, res) => { - admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get() - .then((data) => { - let posts = []; - data.forEach(function(doc) { - posts.push(doc.data()); - }); - return res.status(200).json(posts); - }) - .catch((err) => { - console.error(err); - return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'}) - }) - } + .then((data) => { + let posts = []; + data.forEach(function(doc) { + posts.push(doc.data()); + }); + return res.status(200).json(posts); + }) + .catch((err) => { + console.error(err); + return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'}) + }) +}; diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 7f5a39a..7e4b018 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -151,19 +151,33 @@ exports.deleteUser = (req, res) => { firebase.auth().onAuthStateChanged(function(user) { currentUser = user; if (currentUser) { + /*db.collection("users").doc(`${currentUser.handle}`).delete() + .then(function() { + res.status(200).send("Removed user from database."); + return; + }) + .catch(function(err) { + res.status(500).send("Failed to remove user from database.", err); + });*/ + + //let ref = db.collection('users'); + //let userDoc = ref.where('userId', '==', currentUser.uid).get(); + //userDoc.ref.delete(); + currentUser.delete() .then(function() { - console.log("User successfully deleted!"); + console.log("User successfully deleted."); res.status(200).send("Deleted user."); return; }) - .catch(function(error) { + .catch(function(err) { console.log("Error deleting user.", err); res.status(500).send("Failed to delete user."); }); - } else { - console.log("Cannot get user"); - res.status(500).send("Cannot get user"); + } + else { + console.log("Cannot get user."); + res.status(500).send("Cannot get user."); } }); }; diff --git a/twistter-frontend/src/pages/Delete.js b/twistter-frontend/src/pages/Delete.js index 22f1682..ab610b1 100644 --- a/twistter-frontend/src/pages/Delete.js +++ b/twistter-frontend/src/pages/Delete.js @@ -7,7 +7,7 @@ import Button from "@material-ui/core/Button"; import withStyles from "@material-ui/core/styles/withStyles"; // Redux stuff -import { deleteUser } from "../redux/actions/userActions"; +import { logoutUser } from "../redux/actions/userActions"; import { connect } from "react-redux"; const styles = { @@ -32,7 +32,7 @@ const styles = { export class Delete extends Component { componentDidMount() { - this.props.deleteUser(); + this.props.logoutUser(); this.props.history.push('/'); } @@ -45,10 +45,10 @@ const mapStateToProps = (state) => ({ user: state.user }); -const mapActionsToProps = { deleteUser }; +const mapActionsToProps = { logoutUser }; Delete.propTypes = { - deleteUser: PropTypes.func.isRequired, + logoutUser: PropTypes.func.isRequired, user: PropTypes.object.isRequired, classes: PropTypes.object.isRequired }; From 8f5020f88141ac215144e9c26a7656db7ae602bd Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Thu, 24 Oct 2019 15:44:53 -0400 Subject: [PATCH 12/19] Fixing editProfile bugs and making the database storage more efficient --- functions/handlers/users.js | 4 +-- functions/util/validator.js | 34 ++++++++++++++++------ twistter-frontend/src/pages/editProfile.js | 8 +++++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 00d8f1c..f40878e 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -125,7 +125,7 @@ exports.login = (req, res) => { }) .catch((err) => { console.error(err); - if (err.code === "auth/wrong-password" || err.code === "auth/invalid-email") { + if (err.code === "auth/wrong-password" || err.code === "auth/invalid-email" || err.code === "auth/user-not-found") { return res .status(403) .json({ general: "Invalid credentials. Please try again." }); @@ -153,7 +153,7 @@ exports.updateProfileInfo = (req, res) => { // TODO: Add functionality for adding/updating profile images // Data validation - const { valid, errors, profileData } = validateUpdateProfileInfo(req.body); + const { valid, errors, profileData } = validateUpdateProfileInfo(req); if (!valid) return res.status(400).json(errors); // Update the database entry for this user diff --git a/functions/util/validator.js b/functions/util/validator.js index c2b1240..8265d6b 100644 --- a/functions/util/validator.js +++ b/functions/util/validator.js @@ -9,23 +9,39 @@ const isEmpty = (str) => { else return false; }; -exports.validateUpdateProfileInfo = (data) => { +exports.validateUpdateProfileInfo = (req) => { + const newData = req.body; + // const oldData = req.userData; let errors = {}; - let profileData = {}; + let profileData = req.userData; // ?: Should users be able to change their handles and emails? - // Only adds the key to the database if the values are not empty - if (!isEmpty(data.firstName)) profileData.firstName = data.firstName.trim(); - if (!isEmpty(data.lastName)) profileData.lastName = data.lastName.trim(); - if (!isEmpty(data.bio)) profileData.bio = data.bio.trim(); + // Deletes any unused keys so that they aren't stored in the database + if (newData.firstName) { + profileData.firstName = newData.firstName.toString().trim(); + } else { + delete profileData.firstName; + } - if (isEmpty(data.email)) { + if (newData.lastName) { + profileData.lastName = newData.lastName.toString().trim(); + } else { + delete profileData.lastName; + } + + if (newData.bio) { + profileData.bio = newData.bio.toString().trim(); + } else { + delete profileData.bio; + } + + if (isEmpty(newData.email)) { errors.email = "Must not be empty."; - } else if (!isEmail(data.email)) { + } else if (!isEmail(newData.email)) { errors.email = "Must be a valid email."; } else { - profileData.email = data.email; + profileData.email = newData.email; } return { diff --git a/twistter-frontend/src/pages/editProfile.js b/twistter-frontend/src/pages/editProfile.js index 3c3c51b..ff6f3f7 100644 --- a/twistter-frontend/src/pages/editProfile.js +++ b/twistter-frontend/src/pages/editProfile.js @@ -88,6 +88,14 @@ export class edit extends Component { handle: this.state.handle, bio: this.state.bio }; + + // Removes all keys from newProfileData that are empty, undefined, or null + Object.keys(newProfileData).forEach(key => { + if (newProfileData[key] === "" || newProfileData[key] === undefined || newProfileData[key] === null) { + delete newProfileData[key]; + } + }) + axios .post("/updateProfileInfo", newProfileData) .then((res) => { From cdbf0fcdc68a2d07e5f0e905e5a9a02ea48e8d04 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 24 Oct 2019 16:24:33 -0400 Subject: [PATCH 13/19] renew adminsdk --- ...ter-e4649-firebase-adminsdk-pgjve-1e57494429.json | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 twistter-e4649-firebase-adminsdk-pgjve-1e57494429.json diff --git a/twistter-e4649-firebase-adminsdk-pgjve-1e57494429.json b/twistter-e4649-firebase-adminsdk-pgjve-1e57494429.json deleted file mode 100644 index d24aa3c..0000000 --- a/twistter-e4649-firebase-adminsdk-pgjve-1e57494429.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "service_account", - "project_id": "twistter-e4649", - "private_key_id": "1e57494429e4fd7d17f6fc28524e14b8e5227596", - "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCyRdMZwXrpf3HB\nsVrGZVoPt+S+ahkT4SCCEWV/Q4O4hVyW277Rs0p7k5ZkZfkhcVVBUqKGMgW/Esvz\npx0VIgpg3gg308kMRmC3MGzYbodjynVyDHatyAZhhUi9cg0N2K9+vSsW5eSmWROe\nfVvB8hvr6m5xGVdJFA7DV4/0vm2cfy+Q/FlFb6vFmQTZtPZzGFf5BKoNMe7pMxey\n4zspAIZgRmxWDbAqqzX0PYk/WbXFgH/wn2X25S+ArHhoay2Hms65/NbWCV6mpFUJ\nYqzrlCn/WcwXGAm7tjmu00yD+bARabImh8R7+PSBaHMQ+SGdri2snIXWsvB/xi9/\nSNFqzHynAgMBAAECggEAVty/zapg1bnTt0FPziBfIA6FpaPzoSSN3uJUFozSdwuA\nAD+E/A9EiO7yFew71egvVrtJVmK0OxQRDSDNglkKPoWg8na+XL1D7a5qMpC0ZlKl\nJBNfljBCr6yuMySJqMf+Rp4siyUr4kO/0/cXyOnLYglhk7j5tzFPOi4FhgZtSRU9\nYckk5wwcBObUFE0Rmqf0gPcI9WuFUkusIjz3rjuEju1/U6E/VV5gHmMuQy3f9LHB\nnsiLAobx9+TGgs12CvkjWYpW5raUCCn5z/EYNPZSt7rg9CSWqXW009HCfTqi6i7o\nNpZ7qpp5DVQdHNFJunSGvI+k44+i8OE7HEY4xXt+OQKBgQDZ/E1QwJQoHuzPkrGW\nAc0a+NQeG8NwaXwsezlvYXMTbL27SxKXC3dzPT1WgNUKpaKj3wLJPar4NgPPSPi3\nqgmcvMqgwm4B+HPbXc1oxBS7/jD3pWJVyPO9Re17Uc0RYV/DORQhWe1Yq7TyMHvl\nbD/KqIvOxswigVxK4JMIxp4s7wKBgQDRXJfb4BHdR7CGfuTVQ19gH5uLgrK9ezBk\nQOLK+u9yBpoKyYSnD3OH/i0wG5bm3rUegzvwHGKKhDfiLbajMIt04n2DuVUm57HQ\n+Jca29V8XMWfhTbu3kDl+OOFmLvPCwg8C9edNTJWUVYu3EbwsyzCQY5TDroWGQdF\n6cQIkAIbyQKBgQCUtWd1UHuCR16cWOHniQEIhnoGtEAHHx9EJShQkLV1qfhhnlxn\nSL5LkpqWubsc0VR74LbA3N4XCJpevdRXT5vRHoZJV3q+w2UeYQaxkxrmCQoU1/GW\nvklxdRQGzg5M7hXrU7Qk8HlXxYPiuSq8n7WBJqyB+uLmI0P4HO6RzRW5ZwKBgBkr\nf5pQkvU+dCuHP+2fvuyogCPCn8iF8ehroJh0mKrlvklDtu36vpH/7eDVwEubRL0Z\nW/BfCT3L7YgEpOtzn6B6xko60tDtlAQijtAM09qysJOgCV2oXLcJOBlMpm+azO+j\nINXmmlmkR680jlbLw7rK9NhpcdfMRIKUOxwobAh5AoGBAJMN6n7Hy8nJRJZ18iHY\n3hEkVbKrLLMMHFDQj5BZQCeAp1v0Fj30RYJWS4hTzR9ht0MtdmPub460lh9hhqCM\nl3UnCJoz00ApF3Z2FRN/l0KpCFD9Gw2Hjyc3u9sEUpqd8G3cg3IZE6eZ6CZWljFT\nHcuQ2cTFdB8bq8oLUxXeY3Yv\n-----END PRIVATE KEY-----\n", - "client_email": "firebase-adminsdk-pgjve@twistter-e4649.iam.gserviceaccount.com", - "client_id": "102241295911303209723", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-pgjve%40twistter-e4649.iam.gserviceaccount.com" -} From 714e6a4e07663aac509abf63ee31e3a215df9157 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 24 Oct 2019 16:24:56 -0400 Subject: [PATCH 14/19] new adminsdk --- ...ter-e4649-firebase-adminsdk-pgjve-382fc005e1.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 twistter-e4649-firebase-adminsdk-pgjve-382fc005e1.json diff --git a/twistter-e4649-firebase-adminsdk-pgjve-382fc005e1.json b/twistter-e4649-firebase-adminsdk-pgjve-382fc005e1.json new file mode 100644 index 0000000..3d3ce5d --- /dev/null +++ b/twistter-e4649-firebase-adminsdk-pgjve-382fc005e1.json @@ -0,0 +1,12 @@ +{ + "type": "service_account", + "project_id": "twistter-e4649", + "private_key_id": "382fc005e17340a21dd39079feca75371330644d", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDL1bwTpEluR6dJ\nVfS/K1d76j2I3Wrn4qSbrTYm4/cAPBPlsBRO0bwrkhr+g0I6rwW/fFz8udjNAFB1\nfDfz769buR6go5us71I5LxMNviIhzFr59ZsEkcnUCgW8G7koicLEjWdstI4lJxZT\nRRolH+SFpPwsQAY399zjdBiCC8STbavVVhe+ChEDl/S2K72W7A7nWSMbLsyGsz2o\nQ9uIG3onwFNE7WRIeObWCxSBKlydMmTJ+p/CsTdFY4fUHb97QsMEmzRJox10kmyt\nP9l5wfJ2wUYvRXRJKq7Mwx1UnLduXP2oe/XvR5fzJLJ780HO6BNBf5IKcTHXHVBA\ne6ZtiL5dAgMBAAECggEAFvfN1NttjXL0KKak3hMA1+z8Y2WqXC1aUFMOMlz8Qhct\nmXNjy8CFAYEvGtVTgHqkR9Vi7PShYfLSc3U8diI155H5H4S6pUaPmfNHTwRzosyn\ncQRPJA6sEqvRGvHMxVfwjbvultMpiTTZpnxiMSNiLqT5PUs26CuSb5bErt1V7dP5\nn/lhY+4rzfXSrw38ZsO/gEvLZ/7iRA+JZgqE3Qs2cD5idxqqOcOLLiW741JpXTmd\n5ug/urJgSyvz+cNo3yHnajEtAxiSfkpU4sUHZ/WWqaRGWxpt3XWILtR9Q/4afPeM\n/T82YvddoW5pUwDpgvZxdVYjopuoxvnS298L0AGySQKBgQDqDD7Yh6SbOR3w4ZN9\nRO7q5KiJbyZmVdZ3lLZddsL/vto9JkUtnLDOMpYnb2TezGfN6ErzAkRQCSUsWK4m\nERbSK6oyUvevhlt/gHGP34uc/OCxGk2D7WCAS3s54ofDt2369tzIpGjsnkYM+h3b\nuZ5lFoWHG1YM3JtgcIIU6UygTwKBgQDe9ArV08wPDuXf4rcldmImQDB7xhGcg9xU\njAKEn5FZW1mvmBy3Sq1qpZj0baZz6eEDn6FBLwH1Ke5gdfrd8WnESUNnFnBBqpA1\nospIgUmKZ1sjyly9CHMQ11Kbzt7+kA9GYZrMbaMjS8M18qFEBZ7CoPLv5DLyabJW\nOkPzTwb/kwKBgQDR3fUkmEzj202bx8pHE97gxfTSd9aJAQN06uaz3GByjyKGnqB9\ni/mGjBnUdrCOj9+s5VT/ntK+qdSpdUODYuOBxiGxSnBK9kFpjTVHe35nYOHiLOHB\nIMPdhtGSUCzJNNvrpBzJ1ZM4SZwq2sSXWFRN9On7Amog0liJG5mpQqGxRQKBgHmP\nzFycF3XaZKH2xm8ppgg/FXBXJYEWMEr07+aJ7kEvWq4wHPAfSoCMe+JB6vDmg2Zr\nYgvdao7W5v83NKpQl5+LZrHNfTWAnxJviSWRQJyzD/Fqw7fZ5Is5K/SCDfn0aC+y\nxilSWhHDnFNM0Hr7KX3rLap43QJpePAk4qnF3AX7AoGBAOe5C1VMKoTapnxvo/FI\nBCvXw05SSEExfXVR0ryoqUxgu1asCkYyJSoWxOZQ+33npQ1/zV1mCXn/lNZcyveW\nZ5/cUw71grW8KBYFrW7LeQIzjZb7xPI3Z4EV0uYd2b69GkQk1buHj/gsswRhGEvx\nJM1DN1SCenbGcVLprM0vVelp\n-----END PRIVATE KEY-----\n", + "client_email": "firebase-adminsdk-pgjve@twistter-e4649.iam.gserviceaccount.com", + "client_id": "102241295911303209723", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-pgjve%40twistter-e4649.iam.gserviceaccount.com" +} From e524bc2811f77ac5c34e6f99730706cad13510b2 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 24 Oct 2019 16:25:19 -0400 Subject: [PATCH 15/19] pass in fbAuth to getUserDetails --- functions/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/index.js b/functions/index.js index 5c728bc..119fa38 100644 --- a/functions/index.js +++ b/functions/index.js @@ -27,7 +27,7 @@ app.post("/signup", signup); // and password app.post("/login", login); -app.get("/getUser/:handle", getUserDetails); +app.get("/getUser/:handle", fbAuth, getUserDetails); // Returns all profile data of the currently logged in user app.get("/getProfileInfo", fbAuth, getProfileInfo); From bdad36957ca9586c837e08a9aad96e9f6dd56f18 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 24 Oct 2019 16:25:29 -0400 Subject: [PATCH 16/19] package lock --- package-lock.json | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/package-lock.json b/package-lock.json index 61107d8..c65b0ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,15 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, + "axios": { + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz", + "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==", + "requires": { + "follow-redirects": "1.5.10", + "is-buffer": "^2.0.2" + } + }, "body-parser": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", @@ -164,6 +173,24 @@ "unpipe": "~1.0.0" } }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + }, + "dependencies": { + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + } + } + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -204,6 +231,11 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz", "integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA==" }, + "is-buffer": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", + "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==" + }, "jwt-decode": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", From 570866ff406ac864146eb03ecd4deb4c382efccd Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 24 Oct 2019 16:27:22 -0400 Subject: [PATCH 17/19] getUserDetail returns only user handle --- functions/handlers/users.js | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 00d8f1c..09ffac0 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -178,37 +178,18 @@ exports.updateProfileInfo = (req, res) => { exports.getUserDetails = (req, res) => { let userData = {}; - db.doc(`/users/${req.params.handle}`) + db.doc(`/getUser/${req.params.handle}`) .get() .then((doc) => { if (doc.exists) { - userData.user = doc.data(); - return db - .collection("post") - .where("userHandle", "==", req.params.handle) - .orderBy("createdAt", "desc") - .get(); + userData.credentials = doc.data(); + return res.status(200).json({userData}); } else { - return res.status(404).json({ + return res.status(400).json({ error: "User not found" }); } }) - .then((data) => { - userData.posts = []; - data.forEach((doc) => { - userData.posts.push({ - body: doc.data().body, - createAt: doc.data().createAt, - userHandle: doc.data().userHandle, - userImage: doc.data().userImage, - likeCount: doc.data().likeCount, - commentCount: doc.data().commentCount, - postId: doc.id - }); - }); - return res.json(userData); - }) .catch((err) => { console.error(err); return res.status(500).json({ error: err.code }); @@ -231,3 +212,5 @@ exports.getAuthenticatedUser = (req, res) => { return res.status(500).json({ error: err.code }); }); }; + + From ac28b3e19e25a7e2df69825c0cb07bf6eb46df4e Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 24 Oct 2019 17:06:44 -0400 Subject: [PATCH 18/19] getUserDetails is now working --- functions/handlers/users.js | 4 ++-- functions/index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 09ffac0..09c3c79 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -178,11 +178,11 @@ exports.updateProfileInfo = (req, res) => { exports.getUserDetails = (req, res) => { let userData = {}; - db.doc(`/getUser/${req.params.handle}`) + db.doc(`/users/${req.body.handle}`) .get() .then((doc) => { if (doc.exists) { - userData.credentials = doc.data(); + userData = doc.data(); return res.status(200).json({userData}); } else { return res.status(400).json({ diff --git a/functions/index.js b/functions/index.js index 119fa38..a718b52 100644 --- a/functions/index.js +++ b/functions/index.js @@ -27,7 +27,7 @@ app.post("/signup", signup); // and password app.post("/login", login); -app.get("/getUser/:handle", fbAuth, getUserDetails); +app.get("/getUser", fbAuth, getUserDetails); // Returns all profile data of the currently logged in user app.get("/getProfileInfo", fbAuth, getProfileInfo); From 37cce6c82821f7a761f07ac3ed538efe11a1ff8e Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 24 Oct 2019 17:48:39 -0400 Subject: [PATCH 19/19] deleted profile.js --- twistter-frontend/src/components/profile/Profile.js | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 twistter-frontend/src/components/profile/Profile.js diff --git a/twistter-frontend/src/components/profile/Profile.js b/twistter-frontend/src/components/profile/Profile.js deleted file mode 100644 index f87513f..0000000 --- a/twistter-frontend/src/components/profile/Profile.js +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; - -import { connect } from 'react-redux'; -import { mergeClasses } from '@material-ui/styles'; - -class Profile extends Component { - render(); - - return -} \ No newline at end of file