feat: implement secure admin authentication system with JWT sessions, middleware protection, and Prisma schema initialization
This commit is contained in:
67
src/app/[locale]/admin/dashboard/page.tsx
Normal file
67
src/app/[locale]/admin/dashboard/page.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
import { verifySession, clearSession } from "@/core/security/session";
|
||||
import { redirect } from "@/i18n/routing";
|
||||
import { getLocale } from "next-intl/server";
|
||||
import { LogOut } from "lucide-react";
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const session = await verifySession();
|
||||
const locale = await getLocale();
|
||||
|
||||
if (!session) {
|
||||
redirect({ href: "/admin/login", locale });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-muted/30">
|
||||
{/* Navbar Minimal Dashboard */}
|
||||
<header className="glass border-b border-border/50 sticky top-0 z-40">
|
||||
<div className="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
|
||||
<div className="flex flex-col">
|
||||
<h1 className="text-xl font-bold tracking-tight">Admin Dashboard</h1>
|
||||
<span className="text-xs text-muted-foreground">{session.email}</span>
|
||||
</div>
|
||||
|
||||
<form action={async () => {
|
||||
"use server";
|
||||
await clearSession();
|
||||
redirect({ href: "/admin/login", locale });
|
||||
}}>
|
||||
<button
|
||||
type="submit"
|
||||
className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-error hover:bg-error/10 hover:border-error/30 border border-transparent rounded-lg transition-colors"
|
||||
>
|
||||
<LogOut size={16} />
|
||||
Sign Out
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="max-w-7xl mx-auto px-6 py-12">
|
||||
<div className="grid gap-6 md:grid-cols-3">
|
||||
{/* Card: Projects */}
|
||||
<div className="p-6 rounded-2xl bg-card border border-border/50 shadow-sm hover:shadow-md transition-shadow">
|
||||
<h2 className="text-lg font-bold mb-2">Projects</h2>
|
||||
<p className="text-sm text-muted-foreground mb-4">Manage portfolio projects and case studies.</p>
|
||||
<div className="text-3xl font-mono font-bold text-accent">--</div>
|
||||
</div>
|
||||
|
||||
{/* Card: Skills */}
|
||||
<div className="p-6 rounded-2xl bg-card border border-border/50 shadow-sm hover:shadow-md transition-shadow">
|
||||
<h2 className="text-lg font-bold mb-2">Tech Stack</h2>
|
||||
<p className="text-sm text-muted-foreground mb-4">Update your skills and technical arsenal.</p>
|
||||
<div className="text-3xl font-mono font-bold text-emerald-500">--</div>
|
||||
</div>
|
||||
|
||||
{/* Card: Messages */}
|
||||
<div className="p-6 rounded-2xl bg-card border border-border/50 shadow-sm hover:shadow-md transition-shadow relative overflow-hidden">
|
||||
<h2 className="text-lg font-bold mb-2">Inbox</h2>
|
||||
<p className="text-sm text-muted-foreground mb-4">Read messages from visitors.</p>
|
||||
<div className="text-3xl font-mono font-bold text-blue-500">--</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
24
src/app/[locale]/admin/login/page.tsx
Normal file
24
src/app/[locale]/admin/login/page.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { LoginForm } from "@/features/auth/login-form";
|
||||
import { verifySession } from "@/core/security/session";
|
||||
import { redirect } from "@/i18n/routing";
|
||||
import { getLocale } from "next-intl/server";
|
||||
|
||||
export default async function LoginPage() {
|
||||
const session = await verifySession();
|
||||
const locale = await getLocale();
|
||||
|
||||
// If already logged in, redirect to dashboard
|
||||
if (session) {
|
||||
redirect({ href: "/admin/dashboard", locale });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center relative p-6 bg-muted/30">
|
||||
<div className="absolute inset-0 grid-pattern opacity-20" />
|
||||
|
||||
<div className="relative z-10 w-full">
|
||||
<LoginForm />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user