From 03c283b38bdcdd5f23460f81ff0608a36e1088ef Mon Sep 17 00:00:00 2001 From: yumandee Date: Mon, 11 Apr 2022 17:07:47 -0400 Subject: [PATCH] fixed issue with google users --- pages/api/user/getSaves.js | 9 ++++++--- pages/profile/[userid].js | 11 +++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pages/api/user/getSaves.js b/pages/api/user/getSaves.js index 8a88bcf..1fb07a7 100644 --- a/pages/api/user/getSaves.js +++ b/pages/api/user/getSaves.js @@ -18,10 +18,13 @@ const getSavesHandler = async (req, res) => { // if user doesnt exist, close the db connection and return status of 404 if (!userResult) { client.close(); - return res.status(404).json({ message: "User not found."} ); + return res.status(404).json({ + message: "User not found.", + savedProperties: [], + } ); } - if (userResult.savedProps !== undefined) { + if (userResult.savedProps) { // Return data console.log("User has saved props: ", userResult.savedProps); @@ -35,7 +38,7 @@ const getSavesHandler = async (req, res) => { client.close(); return res.status(200).json({ message: "Property saved!", - savedProperties: null + savedProperties: [] }); } } catch (error) { diff --git a/pages/profile/[userid].js b/pages/profile/[userid].js index c71d516..557877e 100644 --- a/pages/profile/[userid].js +++ b/pages/profile/[userid].js @@ -29,8 +29,8 @@ const fetchUserSavedPropertiesHandler = async (id) => { "Content-Type": "application/json", }, }); - - return response; + const data = await response.json(); + return data.savedProperties || null; } // fetch reviews that this user has made @@ -256,12 +256,7 @@ export async function getServerSideProps({ params: { userid }, req }) { let fetchedProperties = []; let reviews = []; if (session) { - const res = await fetchUserSavedPropertiesHandler(session.user); - - if (res) { - const data = await res.json(); - savedProps = await data.savedProperties; - } + savedProps = await fetchUserSavedPropertiesHandler(session.user); if(savedProps && savedProps.length > 0){ const options = recommendPropSearch(savedProps);