Skip to content

Commit

Permalink
fix(core): check for auth on account pages
Browse files Browse the repository at this point in the history
  • Loading branch information
deini committed Apr 16, 2024
1 parent 1fa1c38 commit 052cadf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-bulldogs-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

check for auth on /account pages
14 changes: 14 additions & 0 deletions apps/core/app/[locale]/(default)/account/layout.tsx
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 1 addition & 8 deletions apps/core/app/[locale]/(default)/account/page.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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 (
<div className="mx-auto">
<h1 className="my-6 my-8 text-4xl font-black lg:my-8 lg:text-5xl">{t('heading')}</h1>
<h1 className="my-8 text-4xl font-black lg:my-8 lg:text-5xl">{t('heading')}</h1>

<div className="mb-14 grid gap-6 md:grid-cols-2 lg:grid-cols-3">
<AccountItem href="/account/orders" title={t('orders')}>
Expand Down

0 comments on commit 052cadf

Please sign in to comment.