Add admin menu link to header when authenticated
- Check isAdminAuthenticated() in Header component - Show 'Admin' link to /admin/orders when user is logged in as admin - Allows quick navigation to admin section after login Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
8edb5e1f5b
commit
6c8d34edde
@@ -8,15 +8,17 @@ import CurrencySelector from './CurrencySelector';
|
|||||||
import MobileNav from './MobileNav';
|
import MobileNav from './MobileNav';
|
||||||
import { prisma } from '@/lib/prisma';
|
import { prisma } from '@/lib/prisma';
|
||||||
import { getCurrentCustomer } from '@/lib/auth';
|
import { getCurrentCustomer } from '@/lib/auth';
|
||||||
|
import { isAdminAuthenticated } from '@/lib/adminAuth';
|
||||||
|
|
||||||
export default async function Header() {
|
export default async function Header() {
|
||||||
const [categories, collections, customer] = await Promise.all([
|
const [categories, collections, customer, isAdmin] = await Promise.all([
|
||||||
prisma.category.findMany({
|
prisma.category.findMany({
|
||||||
where: { showOnPersonalised: true },
|
where: { showOnPersonalised: true },
|
||||||
orderBy: { name: 'asc' },
|
orderBy: { name: 'asc' },
|
||||||
}),
|
}),
|
||||||
prisma.collection.findMany({ orderBy: { name: 'asc' } }),
|
prisma.collection.findMany({ orderBy: { name: 'asc' } }),
|
||||||
getCurrentCustomer(),
|
getCurrentCustomer(),
|
||||||
|
isAdminAuthenticated(),
|
||||||
]);
|
]);
|
||||||
const personalisedLinks = [
|
const personalisedLinks = [
|
||||||
{ href: '/made-to-order', label: 'Shop all' },
|
{ href: '/made-to-order', label: 'Shop all' },
|
||||||
@@ -69,6 +71,11 @@ export default async function Header() {
|
|||||||
</nav>
|
</nav>
|
||||||
<div className="flex items-center gap-2 sm:gap-4">
|
<div className="flex items-center gap-2 sm:gap-4">
|
||||||
<CurrencySelector />
|
<CurrencySelector />
|
||||||
|
{isAdmin && (
|
||||||
|
<Link href="/admin/orders" className="tag-label hover:text-ink">
|
||||||
|
Admin
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
<div className="hidden md:block">
|
<div className="hidden md:block">
|
||||||
<AccountMenu customer={customer ? { name: customer.name, email: customer.email } : null} />
|
<AccountMenu customer={customer ? { name: customer.name, email: customer.email } : null} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user