File size: 2,144 Bytes
304bdf5
 
 
 
 
 
5480d48
 
 
304bdf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5480d48
 
304bdf5
 
 
 
 
 
5480d48
304bdf5
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { redirect } from "next/navigation";
import { auth } from "@/lib/auth";
import { headers } from "next/headers";
import Link from "next/link";
import { Shield, BarChart3, ListFilter, Scissors, ArrowLeft } from "lucide-react";
import { Button } from "@/components/ui/button";
import { AdminNav } from "./admin-nav";

import { UserNav } from "@/components/auth/user-nav";

export default async function AdminLayout({
    children,
}: {
    children: React.ReactNode;
}) {
    const session = await auth.api.getSession({
        headers: await headers()
    });

    const adminEmails = process.env.ADMIN_EMAILS?.split(",") || [];
    if (!session?.user?.email || !adminEmails.includes(session.user.email)) {
        redirect("/login?callbackUrl=/admin/dashboard");
    }

    return (
        <div className="flex min-h-screen flex-col bg-background">
            <header className="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
                <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 flex h-16 items-center gap-4">
                    <Link href="/admin/dashboard" className="flex items-center gap-2 font-bold hover:opacity-80 transition-opacity">
                        <Shield className="h-5 w-5 text-primary" />
                        <span className="hidden sm:inline-block">Vault Admin</span>
                    </Link>
                    <AdminNav />
                    <div className="ml-auto flex items-center gap-4">
                        <Button variant="ghost" size="sm" asChild className="text-muted-foreground hover:text-foreground">
                            <Link href="/dashboard">
                                <ArrowLeft className="mr-2 h-4 w-4" />
                                Exit Admin
                            </Link>
                        </Button>
                        <UserNav />
                    </div>
                </div>
            </header>
            <main className="flex-1 max-w-7xl mx-auto w-full px-4 sm:px-6 lg:px-8 py-8">
                {children}
            </main>
        </div>
    );
}