From bc3a47e2647745cefef80c65a69dbe76ff0acea0 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 10:14:25 -0700 Subject: [PATCH 01/10] correcetd route and method for delete route --- Server/routes/pageSpeedCheckRoute.js | 30 +++++++++------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/Server/routes/pageSpeedCheckRoute.js b/Server/routes/pageSpeedCheckRoute.js index 0881a3bd5..d4d06820a 100644 --- a/Server/routes/pageSpeedCheckRoute.js +++ b/Server/routes/pageSpeedCheckRoute.js @@ -9,13 +9,9 @@ const Monitor = require("../models/Monitor"); * @param {string} monitorId - The ID of the monitor * @middleware verifyOwnership - Ensures the user owns the monitor */ -router.post( - "/:monitorId", - verifyOwnership(Monitor, "monitorId"), - () => { - console.log("Create check"); - } -); +router.post("/:monitorId", verifyOwnership(Monitor, "monitorId"), () => { + console.log("Create check"); +}); /** * @route GET /:monitorId @@ -24,13 +20,9 @@ router.post( * @param {string} monitorId - The ID of the monitor * @middleware verifyOwnership - Ensures the user owns the monitor */ -router.get( - "/:monitorId", - verifyOwnership(Monitor, "monitorId"), - () => { - console.log("Get checks"); - } -); +router.get("/:monitorId", verifyOwnership(Monitor, "monitorId"), () => { + console.log("Get checks"); +}); /** * @route POST /delete/:monitorId @@ -39,12 +31,8 @@ router.get( * @param {string} monitorId - The ID of the monitor * @middleware verifyOwnership - Ensures the user owns the monitor */ -router.post( - "/delete/:monitorId", - verifyOwnership(Monitor, "monitorId"), - () => { - console.log("Delete checks"); - } -); +router.delete("/:monitorId", verifyOwnership(Monitor, "monitorId"), () => { + console.log("Delete checks"); +}); module.exports = router; From 784957bb25fed118324842b551e42d04b916494b Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 11:06:28 -0700 Subject: [PATCH 02/10] Add listener to BasicTable --- Client/src/Components/BasicTable/index.jsx | 24 ++++++++++++++++++-- Client/src/Components/MonitorTable/index.jsx | 16 ++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Client/src/Components/BasicTable/index.jsx b/Client/src/Components/BasicTable/index.jsx index a80c7bfb6..7457b7abf 100644 --- a/Client/src/Components/BasicTable/index.jsx +++ b/Client/src/Components/BasicTable/index.jsx @@ -20,6 +20,7 @@ import PropTypes from "prop-types"; * @param {Array} props.headers - Array of header titles for the table. * @param {Array} props.rowItems - Array of row data objects for the table. * @param {boolean} props.paginated - Flag to enable pagination. + * @param {function} props.handleClick - Function to handle click on row. * * @example * @@ -47,6 +48,10 @@ import PropTypes from "prop-types"; * { id: 3, data:
5
}, * // More rows... * ]; + * + * ROW CLICK HANDLING + * If you want to set a listener for a row click, you can add a handleClick function to FIRST ITEM IN EACH ROW + * * */ @@ -94,7 +99,14 @@ const BasicTable = ({ headers, rowItems, paginated }) => { {paginated === false && Object.keys(groupedRowItems).map((key) => { return ( - + { + groupedRowItems[key].items[0].item.handleClick + ? groupedRowItems[key].items[0].item.handleClick() + : null; + }} + key={groupedRowItems[key].idx} + > {groupedRowItems[key].items.map(({ item }) => { return {item.data}; })} @@ -103,7 +115,14 @@ const BasicTable = ({ headers, rowItems, paginated }) => { })} {paginated === true && paginatedRowsKeys.map((key) => ( - + { + groupedRowItems[key].items[0].item.handleClick + ? groupedRowItems[key].items[0].item.handleClick() + : null; + }} + key={groupedRowItems[key].idx} + > {groupedRowItems[key].items.map(({ item }) => ( {item.data} ))} @@ -141,6 +160,7 @@ BasicTable.propTypes = { }) ).isRequired, paginated: PropTypes.bool, + handleClick: PropTypes.func, }; export default BasicTable; diff --git a/Client/src/Components/MonitorTable/index.jsx b/Client/src/Components/MonitorTable/index.jsx index 338ebb793..536c2c019 100644 --- a/Client/src/Components/MonitorTable/index.jsx +++ b/Client/src/Components/MonitorTable/index.jsx @@ -106,13 +106,23 @@ const MonitorTable = ({ monitors = [] }) => { ? "var(--env-var-color-17)" : "var(--env-var-color-19)", }; - data.push({ id: data.length + 1, data: }); - data.push({ id: data.length + 1, data: }); data.push({ id: data.length + 1, + data: , + handleClick: () => { + console.log(monitor._id); + }, + }); + data.push({ + id: data.length + 1, + data: , + }); + data.push({ + id: data.length + 1, + data: , }); - data.push({ id: data.length + 1, data: "TODO" }); + data.push({ id: data.length + 1, itemId: monitor._id, data: "TODO" }); }); return ; From 0b74175e9c0492bb5f3c018f96ee2621bd7c083c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 11:10:45 -0700 Subject: [PATCH 03/10] Merged chagnes --- Client/src/Components/MonitorTable/index.jsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Client/src/Components/MonitorTable/index.jsx b/Client/src/Components/MonitorTable/index.jsx index 338ebb793..6904978c8 100644 --- a/Client/src/Components/MonitorTable/index.jsx +++ b/Client/src/Components/MonitorTable/index.jsx @@ -3,6 +3,7 @@ import PropTypes from "prop-types"; import ResponseTimeChart from "../Charts/ResponseTimeChart"; import BasicTable from "../BasicTable"; import OpenInNewPage from "../../assets/icons/open-in-new-page.svg?react"; +import { useNavigate } from "react-router-dom"; /** * Host component. @@ -80,6 +81,8 @@ const Status = ({ params }) => { * @returns {React.Component} Returns a table with the monitor data. */ const MonitorTable = ({ monitors = [] }) => { + const navigate = useNavigate(); + const headers = [ { id: 1, name: "Host" }, { id: 2, name: "Status" }, @@ -106,8 +109,17 @@ const MonitorTable = ({ monitors = [] }) => { ? "var(--env-var-color-17)" : "var(--env-var-color-19)", }; - data.push({ id: data.length + 1, data: }); - data.push({ id: data.length + 1, data: }); + data.push({ + id: data.length + 1, + data: , + handleClick: () => { + navigate(`/monitors/${monitor._id}`); + }, + }); + data.push({ + id: data.length + 1, + data: , + }); data.push({ id: data.length + 1, data: , From cc9c439c8d8d4f08bc01736b259165d1d2e1e252 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 13:21:45 -0700 Subject: [PATCH 04/10] Excised insanity from Basic Table --- Client/src/Components/BasicTable/index.jsx | 161 +++++++++---------- Client/src/Components/MonitorTable/index.jsx | 58 +++---- Client/src/Pages/Details/index.jsx | 1 - 3 files changed, 95 insertions(+), 125 deletions(-) diff --git a/Client/src/Components/BasicTable/index.jsx b/Client/src/Components/BasicTable/index.jsx index 7457b7abf..705872033 100644 --- a/Client/src/Components/BasicTable/index.jsx +++ b/Client/src/Components/BasicTable/index.jsx @@ -17,45 +17,52 @@ import PropTypes from "prop-types"; * * @component * @param {Object} props - Component props. - * @param {Array} props.headers - Array of header titles for the table. - * @param {Array} props.rowItems - Array of row data objects for the table. - * @param {boolean} props.paginated - Flag to enable pagination. - * @param {function} props.handleClick - Function to handle click on row. + * @param {Object} props.data - Data for the table including columns and rows. + * @param {Array} props.data.cols - Array of objects for column headers. + * @param {number} props.data.cols[].id - Unique identifier for the column. + * @param {string} props.data.cols[].name - Name of the column to display as header. + * @param {Array} props.data.rows - Array of row objects. + * @param {number} props.data.rows[].id - Unique identifier for the row. + * @param {Array} props.data.rows[].data - Array of cell data objects for the row. + * @param {number} props.data.rows[].data[].id - Unique identifier for the cell. + * @param {JSX.Element} props.data.rows[].data[].data - The content to display in the cell. + * @param {functio} props.data.rows.data.handleClick - Function to call when the row is clicked. + * @param {boolean} [props.paginated=false] - Flag to enable pagination. * * @example + * const data = { + * cols: [ + * { id: 1, name: "First Col" }, + * { id: 2, name: "Second Col" }, + * { id: 3, name: "Third Col" }, + * { id: 4, name: "Fourth Col" }, + * ], + * rows: [ + * { + * id: 1, + * data: [ + * { id: 1, data:
Data for Row 1 Col 1
}, + * { id: 2, data:
Data for Row 1 Col 2
}, + * { id: 3, data:
Data for Row 1 Col 3
}, + * { id: 4, data:
Data for Row 1 Col 4
}, + * ], + * }, + * { + * id: 2, + * data: [ + * { id: 5, data:
Data for Row 2 Col 1
}, + * { id: 6, data:
Data for Row 2 Col 2
}, + * { id: 7, data:
Data for Row 2 Col 3
}, + * { id: 8, data:
Data for Row 2 Col 4
}, + * ], + * }, + * ], + * }; * - * Headers is an array of objets that have a unique ID and a name - * Rows is an array of objects that have a unique ID and some data to display - * Row data can be any valid React node - * Rows are split into groups according to the number of headers, so if you have 3 headers then - * Rows will go under the index % 3 column. - * ie: Row 0 -> col 0 % 3 = 0 - * ie: Row 1 -> col 1 % 3 = 1 - * ie: Row 2 -> col 2 % 3 = 2 - * ie: Row 3 -> col 3 % 3 = 0 - * - * Thus items are put in their correct columns - * - * - * const headers = [ - * { id: 1, name: "ID" }, - * { id: 2, name: "Name" }, - * { id: 3, name: "Age" }, - * ]; - * const rows = [ - * { id: 1, data: 999 }, - * { id: 2, data:
Alex Holliday
}, - * { id: 3, data:
5
}, - * // More rows... - * ]; - * - * ROW CLICK HANDLING - * If you want to set a listener for a row click, you can add a handleClick function to FIRST ITEM IN EACH ROW - * - * + * */ -const BasicTable = ({ headers, rowItems, paginated }) => { +const BasicTable = ({ data, paginated }) => { // Add headers to props validation const [page, setPage] = useState(0); @@ -70,19 +77,13 @@ const BasicTable = ({ headers, rowItems, paginated }) => { setPage(0); // Reset to first page after changing rows per page }; - const numOfCols = headers.length; - - const groupedRowItems = rowItems.reduce((acc, item, idx) => { - const rowIndex = Math.floor((item.id - 1) / numOfCols); - if (!acc[rowIndex]) acc[rowIndex] = { items: [], idx }; - acc[rowIndex].items.push({ item }); - return acc; - }, {}); - - const paginatedRowsKeys = Object.keys(groupedRowItems).slice( - page * rowsPerPage, - page * rowsPerPage + rowsPerPage - ); + let paginatedData = []; + if (paginated) { + paginatedData = data.rows.slice( + page * rowsPerPage, + page * rowsPerPage + rowsPerPage + ); + } return ( <> @@ -90,56 +91,52 @@ const BasicTable = ({ headers, rowItems, paginated }) => { - {headers.map((header) => { - return {header.name}; - })} + {data.cols.map((col) => ( + {col.name} + ))} {paginated === false && - Object.keys(groupedRowItems).map((key) => { + data.rows.map((row) => { return ( { - groupedRowItems[key].items[0].item.handleClick - ? groupedRowItems[key].items[0].item.handleClick() - : null; - }} - key={groupedRowItems[key].idx} + sx={{ cursor: row.handleClick ? "pointer" : "default" }} + key={row.id} + onClick={row.handleClick ? row.handleClick : null} > - {groupedRowItems[key].items.map(({ item }) => { - return {item.data}; + {row.data.map((cell) => { + return {cell.data}; })} ); })} {paginated === true && - paginatedRowsKeys.map((key) => ( - { - groupedRowItems[key].items[0].item.handleClick - ? groupedRowItems[key].items[0].item.handleClick() - : null; - }} - key={groupedRowItems[key].idx} - > - {groupedRowItems[key].items.map(({ item }) => ( - {item.data} - ))} - - ))} + paginatedData.map((row) => { + return ( + + {row.data.map((cell) => { + return {cell.data}; + })} + + ); + })}
{paginated === true && ( )} @@ -147,20 +144,8 @@ const BasicTable = ({ headers, rowItems, paginated }) => { }; BasicTable.propTypes = { - headers: PropTypes.arrayOf( - PropTypes.shape({ - id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, - name: PropTypes.string.isRequired, - }) - ).isRequired, - rowItems: PropTypes.arrayOf( - PropTypes.shape({ - id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, - data: PropTypes.node, - }) - ).isRequired, + data: PropTypes.object.isRequired, paginated: PropTypes.bool, - handleClick: PropTypes.func, }; export default BasicTable; diff --git a/Client/src/Components/MonitorTable/index.jsx b/Client/src/Components/MonitorTable/index.jsx index f26b44a78..35b7a0fca 100644 --- a/Client/src/Components/MonitorTable/index.jsx +++ b/Client/src/Components/MonitorTable/index.jsx @@ -83,14 +83,17 @@ const Status = ({ params }) => { const MonitorTable = ({ monitors = [] }) => { const navigate = useNavigate(); - const headers = [ - { id: 1, name: "Host" }, - { id: 2, name: "Status" }, - { id: 3, name: "Response Time" }, - { id: 4, name: "Actions" }, - ]; - const data = []; - monitors.forEach((monitor) => { + const data = { + cols: [ + { id: 1, name: "Host" }, + { id: 2, name: "Status" }, + { id: 3, name: "Response Time" }, + { id: 4, name: "Actions" }, + ], + rows: [], + }; + + data.rows = monitors.map((monitor, idx) => { const params = { url: monitor.url, title: monitor.name, @@ -109,37 +112,20 @@ const MonitorTable = ({ monitors = [] }) => { ? "var(--env-var-color-17)" : "var(--env-var-color-19)", }; - data.push({ - id: data.length + 1, - data: , - handleClick: () => { - navigate(`/monitors/${monitor._id}`); - }, - }); - data.push({ - id: data.length + 1, - data: , - }); - data.push({ - id: data.length + 1, - data: , - handleClick: () => { - console.log(monitor._id); - }, - }); - data.push({ - id: data.length + 1, - data: , - }); - data.push({ - id: data.length + 1, - data: , - }); - data.push({ id: data.length + 1, itemId: monitor._id, data: "TODO" }); + return { + id: monitor._id, + handleClick: () => navigate(`/monitors/${monitor._id}`), + data: [ + { id: idx, data: }, + { id: idx + 1, data: }, + { id: idx + 2, data: }, + { id: idx + 3, data: "TODO" }, + ], + }; }); - return ; + return ; }; MonitorTable.propTypes = { diff --git a/Client/src/Pages/Details/index.jsx b/Client/src/Pages/Details/index.jsx index 488b2b6ab..201a32524 100644 --- a/Client/src/Pages/Details/index.jsx +++ b/Client/src/Pages/Details/index.jsx @@ -27,7 +27,6 @@ const DetailsPage = () => { const theme = useTheme(); - // Example monitor data (replace with actual data or fetch from API) /** * Function to calculate uptime duration based on the most recent check. * @param {Array} checks Array of check objects. From e0d3dd0331dc48045225eaa15d772d99ab55f1f1 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 13:27:58 -0700 Subject: [PATCH 05/10] Further simplified --- Client/src/Components/BasicTable/index.jsx | 51 +++++++--------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/Client/src/Components/BasicTable/index.jsx b/Client/src/Components/BasicTable/index.jsx index 705872033..f006a3a48 100644 --- a/Client/src/Components/BasicTable/index.jsx +++ b/Client/src/Components/BasicTable/index.jsx @@ -77,13 +77,9 @@ const BasicTable = ({ data, paginated }) => { setPage(0); // Reset to first page after changing rows per page }; - let paginatedData = []; - if (paginated) { - paginatedData = data.rows.slice( - page * rowsPerPage, - page * rowsPerPage + rowsPerPage - ); - } + let displayData = paginated + ? data.rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) + : data.rows; return ( <> @@ -97,34 +93,19 @@ const BasicTable = ({ data, paginated }) => {
- {paginated === false && - data.rows.map((row) => { - return ( - - {row.data.map((cell) => { - return {cell.data}; - })} - - ); - })} - {paginated === true && - paginatedData.map((row) => { - return ( - - {row.data.map((cell) => { - return {cell.data}; - })} - - ); - })} + {displayData.map((row) => { + return ( + + {row.data.map((cell) => { + return {cell.data}; + })} + + ); + })} From f985884cea986d69693a2d8481ff8f846fe60082 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 13:30:11 -0700 Subject: [PATCH 06/10] Fix typo --- Client/src/Components/BasicTable/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/src/Components/BasicTable/index.jsx b/Client/src/Components/BasicTable/index.jsx index f006a3a48..a1c3afef2 100644 --- a/Client/src/Components/BasicTable/index.jsx +++ b/Client/src/Components/BasicTable/index.jsx @@ -26,7 +26,7 @@ import PropTypes from "prop-types"; * @param {Array} props.data.rows[].data - Array of cell data objects for the row. * @param {number} props.data.rows[].data[].id - Unique identifier for the cell. * @param {JSX.Element} props.data.rows[].data[].data - The content to display in the cell. - * @param {functio} props.data.rows.data.handleClick - Function to call when the row is clicked. + * @param {function} props.data.rows.data.handleClick - Function to call when the row is clicked. * @param {boolean} [props.paginated=false] - Flag to enable pagination. * * @example From ce200eeb20a4da2a860ef7a5b4a294b95443dfea Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 14:06:51 -0700 Subject: [PATCH 07/10] Reset password returns a token --- Server/controllers/authController.js | 4 ++-- Server/db/MongoDB.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Server/controllers/authController.js b/Server/controllers/authController.js index 979a0b87e..a4fe598d1 100644 --- a/Server/controllers/authController.js +++ b/Server/controllers/authController.js @@ -309,11 +309,11 @@ const validateRecoveryTokenController = async (req, res, next) => { const resetPasswordController = async (req, res, next) => { try { await newPasswordValidation.validateAsync(req.body); - user = await req.db.resetPassword(req, res); + const token = await req.db.resetPassword(req, res); res.status(200).json({ success: true, msg: successMessages.AUTH_RESET_PASSWORD, - data: user, + data: token, }); } catch (error) { error.service = SERVICE_NAME; diff --git a/Server/db/MongoDB.js b/Server/db/MongoDB.js index c0b0948a2..1170134de 100644 --- a/Server/db/MongoDB.js +++ b/Server/db/MongoDB.js @@ -220,7 +220,8 @@ const resetPassword = async (req, res) => { }) .select("-password") .select("-profileImage"); - return userWithoutPassword; + const token = issueToken(userWithoutPassword); + return token; } else { throw new Error(errorMessages.DB_USER_NOT_FOUND); } From 6ddbbdc1226c8c3b455eef575d6405e18084bcec Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 14:16:45 -0700 Subject: [PATCH 08/10] Cleanup --- Client/src/Components/Host/index.jsx | 18 ----- Client/src/Components/HostActions/index.jsx | 8 --- Client/src/Components/HostStatus/index.jsx | 18 ----- Client/src/Components/HostsTable/index.jsx | 80 --------------------- Client/src/Pages/Details/index.jsx | 1 - 5 files changed, 125 deletions(-) delete mode 100644 Client/src/Components/Host/index.jsx delete mode 100644 Client/src/Components/HostActions/index.jsx delete mode 100644 Client/src/Components/HostStatus/index.jsx delete mode 100644 Client/src/Components/HostsTable/index.jsx diff --git a/Client/src/Components/Host/index.jsx b/Client/src/Components/Host/index.jsx deleted file mode 100644 index 370745f4d..000000000 --- a/Client/src/Components/Host/index.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import React from "react"; -import OpenIt from "../../assets/Images/Icon-open-in-tab-gray.png"; - -function Host(title, precentage, statusColor, link) { - return ( -
- - OpenIt - -
{title}
-
- {precentage}% -
-
- ); -} - -export default Host; diff --git a/Client/src/Components/HostActions/index.jsx b/Client/src/Components/HostActions/index.jsx deleted file mode 100644 index c974906e8..000000000 --- a/Client/src/Components/HostActions/index.jsx +++ /dev/null @@ -1,8 +0,0 @@ -import React from "react"; -import DashboardSettings from "../DashboardSettingsIcon"; - -function HostActions() { - return ; -} - -export default HostActions; diff --git a/Client/src/Components/HostStatus/index.jsx b/Client/src/Components/HostStatus/index.jsx deleted file mode 100644 index 3b0660c33..000000000 --- a/Client/src/Components/HostStatus/index.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import React from "react"; - -function HostStatus(backgroundColor, status, dotColor) { - return ( -
-
-
{status}
-
- ); -} - -export default HostStatus; diff --git a/Client/src/Components/HostsTable/index.jsx b/Client/src/Components/HostsTable/index.jsx deleted file mode 100644 index bc1dc1ff9..000000000 --- a/Client/src/Components/HostsTable/index.jsx +++ /dev/null @@ -1,80 +0,0 @@ -import PropTypes from "prop-types"; -import Host from "../Host/"; -import HostStatus from "../HostStatus"; -import ResponseTimeChart from "../Charts/ResponseTimeChart"; -/** - * HostsTable displays the current status of monitor - * - * @component - * @param {Array} monitors - An array of monitor objects to be displayed. - */ - -const getLastCheckStatus = (monitor) => { - if (monitor.checks.length === 0) { - // Default values for when there are no checks - return { - color: "var(--env-var-color-21)", - statusText: "No Data", - dotColor: "var(--env-var-color-19)", - }; - } - - const lastCheck = monitor.checks[monitor.checks.length - 1]; - const isUp = lastCheck.status === true; - return { - color: isUp ? "var(--env-var-color-20)" : "var(--env-var-color-21)", - statusText: isUp ? "Up" : "Down", - dotColor: isUp ? "var(--env-var-color-17)" : "var(--env-var-color-19)", - }; -}; - -const HostsTable = ({ monitors }) => { - return ( -
- - - - - - - - - - - {monitors.map((monitor) => { - const host = Host( - monitor.name, - 100, - "var(--env-var-color-17)", - monitor.url - ); - - const { color, currentStatus, dotColor } = - getLastCheckStatus(monitor); - - const status = HostStatus(color, currentStatus, dotColor); - - return ( - - - - - - - ); - })} - -
HostStatusResponseActions
{host}{status} - - - {monitor.actions} -
-
- ); -}; - -HostsTable.propTypes = { - monitors: PropTypes.arrayOf(PropTypes.object).isRequired, -}; - -export default HostsTable; diff --git a/Client/src/Pages/Details/index.jsx b/Client/src/Pages/Details/index.jsx index 201a32524..c8cd6be7a 100644 --- a/Client/src/Pages/Details/index.jsx +++ b/Client/src/Pages/Details/index.jsx @@ -1,5 +1,4 @@ import React, { useEffect, useState } from "react"; -import CustomizedTables from "../../Components/CustomizedTables"; import { Box, Typography, useTheme } from "@mui/material"; import { useSelector } from "react-redux"; import { useParams } from "react-router-dom"; From 61d65f700ee4bbe1c1492b16098a8e0b89de21f1 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 14:23:42 -0700 Subject: [PATCH 09/10] Add user to response --- Server/controllers/authController.js | 4 ++-- Server/db/MongoDB.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/controllers/authController.js b/Server/controllers/authController.js index a4fe598d1..51ee2dac1 100644 --- a/Server/controllers/authController.js +++ b/Server/controllers/authController.js @@ -309,11 +309,11 @@ const validateRecoveryTokenController = async (req, res, next) => { const resetPasswordController = async (req, res, next) => { try { await newPasswordValidation.validateAsync(req.body); - const token = await req.db.resetPassword(req, res); + const response = await req.db.resetPassword(req, res); res.status(200).json({ success: true, msg: successMessages.AUTH_RESET_PASSWORD, - data: token, + data: response, }); } catch (error) { error.service = SERVICE_NAME; diff --git a/Server/db/MongoDB.js b/Server/db/MongoDB.js index 1170134de..4b225b543 100644 --- a/Server/db/MongoDB.js +++ b/Server/db/MongoDB.js @@ -221,7 +221,7 @@ const resetPassword = async (req, res) => { .select("-password") .select("-profileImage"); const token = issueToken(userWithoutPassword); - return token; + return { user: userWithoutPassword, token: token }; } else { throw new Error(errorMessages.DB_USER_NOT_FOUND); } From f16980969239bc88a8a69896652ddf278098393e Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 16 Jul 2024 14:40:37 -0700 Subject: [PATCH 10/10] Fixed token issue --- Server/controllers/authController.js | 5 +++-- Server/db/MongoDB.js | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Server/controllers/authController.js b/Server/controllers/authController.js index 51ee2dac1..1cab8703e 100644 --- a/Server/controllers/authController.js +++ b/Server/controllers/authController.js @@ -309,11 +309,12 @@ const validateRecoveryTokenController = async (req, res, next) => { const resetPasswordController = async (req, res, next) => { try { await newPasswordValidation.validateAsync(req.body); - const response = await req.db.resetPassword(req, res); + const user = await req.db.resetPassword(req, res); + const token = issueToken(user); res.status(200).json({ success: true, msg: successMessages.AUTH_RESET_PASSWORD, - data: response, + data: { user, token }, }); } catch (error) { error.service = SERVICE_NAME; diff --git a/Server/db/MongoDB.js b/Server/db/MongoDB.js index 4b225b543..c0b0948a2 100644 --- a/Server/db/MongoDB.js +++ b/Server/db/MongoDB.js @@ -220,8 +220,7 @@ const resetPassword = async (req, res) => { }) .select("-password") .select("-profileImage"); - const token = issueToken(userWithoutPassword); - return { user: userWithoutPassword, token: token }; + return userWithoutPassword; } else { throw new Error(errorMessages.DB_USER_NOT_FOUND); }