Skip to content

Commit

Permalink
fix: isloggedIn logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Udit-takkar committed Jan 21, 2025
1 parent 5548e08 commit 4fe51a9
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,24 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
});

const userId = session?.user?.id;
const isLoggedInUserHost =
userId &&
(eventType.users.some((user) => user.id === userId) ||
eventType.hosts.some(({ user }) => user.id === userId));

const checkIfUserIsHost = (userId?: number | null) => {
if (!userId) return false;

return (
bookingInfo?.user?.id === userId ||
eventType.users.some(
(user) =>
user.id === userId && bookingInfo.attendees.some((attendee) => attendee.email === user.email)
) ||
eventType.hosts.some(
({ user }) =>
user.id === userId && bookingInfo.attendees.some((attendee) => attendee.email === user.email)
)
);
};

const isLoggedInUserHost = checkIfUserIsHost(userId);

if (!isLoggedInUserHost) {
// Removing hidden fields from responses
Expand Down

0 comments on commit 4fe51a9

Please sign in to comment.