diff --git a/app/messages/page.jsx b/app/messages/page.jsx index 8f4f88e..e829dcb 100644 --- a/app/messages/page.jsx +++ b/app/messages/page.jsx @@ -11,6 +11,7 @@ const MessagePage = async () => { const sessionUser = await getSessionUser(); const { userId } = sessionUser; + console.log(userId); const readMessages = await Message.find({ recipient: userId, read: true }) .sort({ createdAt: -1 }) // Sort read messages in asc order diff --git a/utils/getSessionUser.js b/utils/getSessionUser.js index 035f1ef..4f952fa 100644 --- a/utils/getSessionUser.js +++ b/utils/getSessionUser.js @@ -2,19 +2,14 @@ import { getServerSession } from 'next-auth/next'; import { authOptions } from '@/utils/authOptions'; export const getSessionUser = async () => { - try { - const session = await getServerSession(authOptions); + const session = await getServerSession(authOptions); - if (!session || !session.user) { - return null; - } - - return { - user: session.user, - userId: session.user.id, - }; - } catch (error) { - console.error(error); + if (!session || !session.user) { return null; } + + return { + user: session.user, + userId: session.user.id, + }; };