From 052cadf43417c2ae2c7ded41bb132e1b7b225ed9 Mon Sep 17 00:00:00 2001 From: Daniel Almaguer Date: Tue, 16 Apr 2024 14:31:32 -0500 Subject: [PATCH] fix(core): check for auth on account pages --- .changeset/silver-bulldogs-hammer.md | 5 +++++ .../core/app/[locale]/(default)/account/layout.tsx | 14 ++++++++++++++ apps/core/app/[locale]/(default)/account/page.tsx | 9 +-------- 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 .changeset/silver-bulldogs-hammer.md create mode 100644 apps/core/app/[locale]/(default)/account/layout.tsx diff --git a/.changeset/silver-bulldogs-hammer.md b/.changeset/silver-bulldogs-hammer.md new file mode 100644 index 000000000..88349360a --- /dev/null +++ b/.changeset/silver-bulldogs-hammer.md @@ -0,0 +1,5 @@ +--- +"@bigcommerce/catalyst-core": patch +--- + +check for auth on /account pages diff --git a/apps/core/app/[locale]/(default)/account/layout.tsx b/apps/core/app/[locale]/(default)/account/layout.tsx new file mode 100644 index 000000000..dc5298fa6 --- /dev/null +++ b/apps/core/app/[locale]/(default)/account/layout.tsx @@ -0,0 +1,14 @@ +import { redirect } from 'next/navigation'; +import { PropsWithChildren } from 'react'; + +import { auth } from '~/auth'; + +export default async function AccountLayout({ children }: PropsWithChildren) { + const session = await auth(); + + if (!session) { + redirect('/login'); + } + + return children; +} diff --git a/apps/core/app/[locale]/(default)/account/page.tsx b/apps/core/app/[locale]/(default)/account/page.tsx index 5eba8e83b..d5206e476 100644 --- a/apps/core/app/[locale]/(default)/account/page.tsx +++ b/apps/core/app/[locale]/(default)/account/page.tsx @@ -1,9 +1,7 @@ import { BookUser, Eye, Gift, Mail, Package, Settings } from 'lucide-react'; -import { redirect } from 'next/navigation'; import { getTranslations } from 'next-intl/server'; import { ReactNode } from 'react'; -import { auth } from '~/auth'; import { Link } from '~/components/link'; import { LocaleType } from '~/i18n'; @@ -36,16 +34,11 @@ interface Props { } export default async function AccountPage({ params: { locale } }: Props) { - const session = await auth(); const t = await getTranslations({ locale, namespace: 'Account.Home' }); - if (!session) { - redirect('/login'); - } - return (
-

{t('heading')}

+

{t('heading')}