Server-rendered CMS at /admin, reachable only with an authenticated admin.
There was no way to change anything on the site without a database session,
while every mutating endpoint used to be anonymous, so the site was either
unmanageable or, before the API lock-down, wide open.
Everything runs through Server Actions, so the httpOnly
parsaaghayi_admin_session cookie set by the backend is read server-side and
forwarded as a bearer token. No token ever reaches client JavaScript and the
browser never talks to the backend cross-origin, so CORS and CSRF do not
apply. Unauthenticated visits to any panel route redirect to /admin/login.
Resources are declared once in a registry (src/app/lib/admin/resources.ts)
and the list, create and edit screens are generated from it, so adding a
content type is a data change rather than three new pages. Covered: posts,
categories, tags, projects, about-me.
Records are read from GET /api/admin/resources/{resource}, which returns
stored rows including every locale; the public endpoints only expose
translated display payloads and cannot populate an editing form.
Verified: tsc --noEmit clean, eslint clean, next build compiles and registers
all five admin routes as dynamic, and /admin, /admin/posts redirect 307 to
/admin/login while /admin/login renders.
Post bodies are rendered as text nodes, never as HTML.
25 lines
798 B
TypeScript
25 lines
798 B
TypeScript
import { redirect } from 'next/navigation';
|
|
import { currentAdmin } from '@/app/lib/admin/api';
|
|
import LoginForm from '@/app/lib/admin/login-form';
|
|
import { Card } from '@/app/lib/admin/ui';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export default async function AdminLoginPage() {
|
|
if (await currentAdmin()) redirect('/admin');
|
|
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center px-4 py-16">
|
|
<Card className="w-full max-w-sm">
|
|
<div className="mb-6">
|
|
<h1 className="text-xl font-bold text-foreground">پنل مدیریت</h1>
|
|
<p className="mt-2 text-sm text-muted-foreground">
|
|
برای مدیریت محتوای سایت وارد شوید.
|
|
</p>
|
|
</div>
|
|
|
|
<LoginForm />
|
|
</Card>
|
|
</div>
|
|
);
|
|
} |