Skip to content

Commit

Permalink
fixed issue with google users
Browse files Browse the repository at this point in the history
  • Loading branch information
yumandee committed Apr 11, 2022
1 parent e9be3f9 commit 03c283b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 6 additions & 3 deletions pages/api/user/getSaves.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -35,7 +38,7 @@ const getSavesHandler = async (req, res) => {
client.close();
return res.status(200).json({
message: "Property saved!",
savedProperties: null
savedProperties: []
});
}
} catch (error) {
Expand Down
11 changes: 3 additions & 8 deletions pages/profile/[userid].js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 03c283b

Please sign in to comment.