Skip to content

Commit

Permalink
fix: check for correct user when displaying reservation
Browse files Browse the repository at this point in the history
  • Loading branch information
vincit-matu committed May 7, 2024
1 parent 43738b2 commit fb08651
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/ui/modules/queries/reservation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const GET_RESERVATION = gql`
calendarUrl
user {
email
pk
}
state
price
Expand Down
10 changes: 7 additions & 3 deletions apps/ui/pages/reservations/[id]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo } from "react";
import type { GetServerSidePropsContext } from "next";
import Error from "next/error";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import styled from "styled-components";
import router from "next/router";
Expand Down Expand Up @@ -402,7 +403,7 @@ function Reservation({
reservation,
}: PropsNarrowed): JSX.Element | null {
const { t, i18n } = useTranslation();
const { isAuthenticated } = useSession();
const { isAuthenticated, user } = useSession();

// TODO this should be moved to SSR also
const { order, isLoading: orderLoading } = useOrder({
Expand Down Expand Up @@ -465,12 +466,15 @@ function Reservation({
return null;
}
}, [reservation]);

;

Check failure on line 469 in apps/ui/pages/reservations/[id]/index.tsx

View workflow job for this annotation

GitHub Actions / Lint ui

Delete `;⏎`
// NOTE should never end up here (SSR redirect to login)
if (!isAuthenticated) {
if (!isAuthenticated || reservation.user?.pk !== user?.pk) {
return <div>{t("common:error.notAuthenticated")}</div>;
}

if (reservation.user?.pk !== user?.pk) {
return <Error statusCode={403} />;
}
const normalizedOrderStatus =
getNormalizedReservationOrderStatus(reservation);

Expand Down

0 comments on commit fb08651

Please sign in to comment.