+12
-11
@@ -25,9 +25,9 @@ import { getAdminMediaAssets } from "@/lib/media";
|
||||
import { getAdminPortfolioCategories, getAdminPortfolioProjects } from "@/lib/portfolio";
|
||||
|
||||
type RootPageProps = {
|
||||
searchParams?: {
|
||||
searchParams?: Promise<{
|
||||
error?: string;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
@@ -61,25 +61,26 @@ const copy = {
|
||||
};
|
||||
|
||||
export default async function RootPage({ searchParams }: RootPageProps) {
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const authConfigured = isAdminAuthConfigured();
|
||||
const basicConfigured = Boolean(
|
||||
process.env.ROOT_BASIC_AUTH_USER && process.env.ROOT_BASIC_AUTH_PASS,
|
||||
);
|
||||
const authenticated = isAdminAuthenticated();
|
||||
const lockState = getAdminLockState();
|
||||
const authenticated = await isAdminAuthenticated();
|
||||
const lockState = await getAdminLockState();
|
||||
|
||||
async function loginAction(formData: FormData) {
|
||||
"use server";
|
||||
|
||||
const password = String(formData.get("password") ?? "");
|
||||
const currentLockState = getAdminLockState();
|
||||
const currentLockState = await getAdminLockState();
|
||||
|
||||
if (currentLockState.locked) {
|
||||
redirect("/?error=locked");
|
||||
}
|
||||
|
||||
if (!isAdminAuthConfigured() || !isPasswordValid(password)) {
|
||||
const failState = registerFailedAdminAttempt();
|
||||
const failState = await registerFailedAdminAttempt();
|
||||
if (failState.locked) {
|
||||
redirect("/?error=locked");
|
||||
}
|
||||
@@ -87,15 +88,15 @@ export default async function RootPage({ searchParams }: RootPageProps) {
|
||||
redirect("/?error=invalid");
|
||||
}
|
||||
|
||||
resetAdminFailedAttempts();
|
||||
setAdminSessionCookie();
|
||||
await resetAdminFailedAttempts();
|
||||
await setAdminSessionCookie();
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
clearAdminSessionCookie();
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
@@ -124,13 +125,13 @@ export default async function RootPage({ searchParams }: RootPageProps) {
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{searchParams?.error === "invalid" ? (
|
||||
{resolvedSearchParams?.error === "invalid" ? (
|
||||
<p className="mb-4 rounded-nested border border-status-warning/30 bg-status-warning-soft px-3 py-2 text-sm text-status-warning">
|
||||
{copy.invalidLogin}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{searchParams?.error === "locked" || lockState.locked ? (
|
||||
{resolvedSearchParams?.error === "locked" || lockState.locked ? (
|
||||
<p className="mb-4 rounded-nested border border-status-warning/30 bg-status-warning-soft px-3 py-2 text-sm text-status-warning">
|
||||
{copy.lockedLogin}
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user