Edit
diff --git a/app/profile/page.jsx b/app/profile/page.jsx
new file mode 100644
index 0000000..4bd9bf2
--- /dev/null
+++ b/app/profile/page.jsx
@@ -0,0 +1,65 @@
+import Image from 'next/image';
+import connectDB from '@/config/database';
+import Property from '@/models/Property';
+import { getSessionUser } from '@/utils/getSessionUser';
+import profileDefault from '@/assets/images/profile.png';
+import ProfileProperties from '@/components/ProfileProperties';
+import { convertToSerializeableObject } from '@/utils/convertToObject';
+
+const ProfilePage = async () => {
+ await connectDB();
+
+ const sessionUser = await getSessionUser();
+
+ const { userId } = sessionUser;
+
+ if (!userId) {
+ throw new Error('User ID is required');
+ }
+
+ const propertiesDocs = await Property.find({ owner: userId }).lean();
+ const properties = propertiesDocs.map(convertToSerializeableObject);
+
+ return (
+
+
+
+
Your Profile
+
+
+
+
+
+
+
+ Name: {' '}
+ {sessionUser.user.name}
+
+
+ Email: {' '}
+ {sessionUser.user.email}
+
+
+
+
+
Your Listings
+ {properties.length === 0 ? (
+
You have no property listings
+ ) : (
+
+ )}
+
+
+
+
+
+ );
+};
+
+export default ProfilePage;
diff --git a/components/ProfileProperties.jsx b/components/ProfileProperties.jsx
new file mode 100644
index 0000000..ea5d61f
--- /dev/null
+++ b/components/ProfileProperties.jsx
@@ -0,0 +1,45 @@
+'use client';
+import { useState } from 'react';
+import Image from 'next/image';
+import Link from 'next/link';
+
+const ProfileProperties = ({ properties: initialProperties }) => {
+ const [properties, setProperties] = useState(initialProperties);
+ return properties.map((property) => (
+
+
+
+
+
+
{property.name}
+
+ Address: {property.location.street} {property.location.city}{' '}
+ {property.location.state}
+
+
+
+
+ Edit
+
+
+
+
+ ));
+};
+
+export default ProfileProperties;
diff --git a/utils/convertToObject.js b/utils/convertToObject.js
new file mode 100644
index 0000000..bba47b5
--- /dev/null
+++ b/utils/convertToObject.js
@@ -0,0 +1,14 @@
+/**
+ * Converts a Mongoose lean document into a serializable plain JavaScript object.
+ *
+ * @param {Object} leanDocument - The Mongoose lean document to be converted.
+ * @returns {Object} A plain JavaScript object that is a serializable representation of the input document.
+ */
+
+export function convertToSerializeableObject(leanDocument) {
+ for (const key of Object.keys(leanDocument)) {
+ if (leanDocument[key].toJSON && leanDocument[key].toString)
+ leanDocument[key] = leanDocument[key].toString();
+ }
+ return leanDocument;
+}