diff --git a/app/src/app/[lng]/[inventory]/page.tsx b/app/src/app/[lng]/[inventory]/page.tsx index affea287a..d0bedabf8 100644 --- a/app/src/app/[lng]/[inventory]/page.tsx +++ b/app/src/app/[lng]/[inventory]/page.tsx @@ -9,6 +9,7 @@ import { CircleIcon } from "@/components/icons"; import { NavigationBar } from "@/components/navigation-bar"; import { useTranslation } from "@/i18n/client"; import { api, useGetCityPopulationQuery } from "@/services/api"; +import { checkUserSession } from "@/util/check-user-session"; import { formatPercent, getShortenNumberUnit, @@ -78,12 +79,7 @@ export default function Home({ params: { lng } }: { params: { lng: string } }) { const toast = useToast(); const router = useRouter(); // Check if user is authenticated otherwise route to login page - const { data, status } = useSession({ - required: true, - onUnauthenticated() { - router.push("/auth/login"); - }, - }); + checkUserSession(); const { inventory: inventoryParam } = useParams(); let inventoryId = inventoryParam as string | null; if (inventoryId === "null" || inventoryId === "undefined") { @@ -392,8 +388,8 @@ export default function Home({ params: { lng } }: { params: { lng: string } }) { /> - {inventory?.city.area! == 0 || - inventory?.city.area === null ? ( + {inventory?.city.area === null || + inventory?.city.area! === 0 ? ( { const defaultInventoryAvailable = !!userInfo?.defaultInventoryId; const defaultInventoryPath = `/${userInfo?.defaultInventoryId}`; diff --git a/app/src/util/check-user-session.ts b/app/src/util/check-user-session.ts new file mode 100644 index 000000000..25e6f3387 --- /dev/null +++ b/app/src/util/check-user-session.ts @@ -0,0 +1,13 @@ +import { useSession } from "next-auth/react"; +import { useRouter } from "next/navigation"; + +export const checkUserSession = () => { + const router = useRouter(); + + const { data, status } = useSession({ + required: true, + onUnauthenticated() { + router.push("/auth/login"); + }, + }); +};