+12
-12
@@ -64,8 +64,8 @@ export function isPasswordValid(password: string): boolean {
|
||||
return timingSafeEqual(provided, expected);
|
||||
}
|
||||
|
||||
export function setAdminSessionCookie(): void {
|
||||
const store = cookies();
|
||||
export async function setAdminSessionCookie(): Promise<void> {
|
||||
const store = await cookies();
|
||||
store.set(ADMIN_SESSION_COOKIE, buildToken(), {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
@@ -75,8 +75,8 @@ export function setAdminSessionCookie(): void {
|
||||
});
|
||||
}
|
||||
|
||||
export function clearAdminSessionCookie(): void {
|
||||
const store = cookies();
|
||||
export async function clearAdminSessionCookie(): Promise<void> {
|
||||
const store = await cookies();
|
||||
store.set(ADMIN_SESSION_COOKIE, "", {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
@@ -108,8 +108,8 @@ function parseFailState(rawValue: string | undefined): FailState {
|
||||
}
|
||||
}
|
||||
|
||||
export function getAdminLockState(): { locked: boolean; remainingSeconds: number } {
|
||||
const store = cookies();
|
||||
export async function getAdminLockState(): Promise<{ locked: boolean; remainingSeconds: number }> {
|
||||
const store = await cookies();
|
||||
const state = parseFailState(store.get(ADMIN_FAIL_COOKIE)?.value);
|
||||
const now = Date.now();
|
||||
|
||||
@@ -123,8 +123,8 @@ export function getAdminLockState(): { locked: boolean; remainingSeconds: number
|
||||
return { locked: false, remainingSeconds: 0 };
|
||||
}
|
||||
|
||||
export function registerFailedAdminAttempt(): { locked: boolean; remainingSeconds: number } {
|
||||
const store = cookies();
|
||||
export async function registerFailedAdminAttempt(): Promise<{ locked: boolean; remainingSeconds: number }> {
|
||||
const store = await cookies();
|
||||
const now = Date.now();
|
||||
const current = parseFailState(store.get(ADMIN_FAIL_COOKIE)?.value);
|
||||
const attempts = current.lockUntil > now ? current.attempts : current.attempts + 1;
|
||||
@@ -145,8 +145,8 @@ export function registerFailedAdminAttempt(): { locked: boolean; remainingSecond
|
||||
};
|
||||
}
|
||||
|
||||
export function resetAdminFailedAttempts(): void {
|
||||
const store = cookies();
|
||||
export async function resetAdminFailedAttempts(): Promise<void> {
|
||||
const store = await cookies();
|
||||
store.set(ADMIN_FAIL_COOKIE, "", {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
@@ -156,12 +156,12 @@ export function resetAdminFailedAttempts(): void {
|
||||
});
|
||||
}
|
||||
|
||||
export function isAdminAuthenticated(): boolean {
|
||||
export async function isAdminAuthenticated(): Promise<boolean> {
|
||||
if (!isAdminAuthConfigured()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const store = cookies();
|
||||
const store = await cookies();
|
||||
const token = store.get(ADMIN_SESSION_COOKIE)?.value;
|
||||
|
||||
if (!token) {
|
||||
|
||||
@@ -8,8 +8,8 @@ import {
|
||||
type ContactProtectionSettings,
|
||||
} from "@/lib/contact-protection";
|
||||
|
||||
function getClientIpFromHeaders() {
|
||||
const requestHeaders = headers();
|
||||
async function getClientIpFromHeaders() {
|
||||
const requestHeaders = await headers();
|
||||
const forwardedFor = requestHeaders.get("x-forwarded-for");
|
||||
|
||||
if (forwardedFor) {
|
||||
@@ -41,7 +41,7 @@ export async function enforceContactRateLimit(settings: ContactProtectionSetting
|
||||
return;
|
||||
}
|
||||
|
||||
const ip = getClientIpFromHeaders();
|
||||
const ip = await getClientIpFromHeaders();
|
||||
const key = getRateLimitKey(ip, settings.rateLimit.windowMinutes);
|
||||
|
||||
await prisma.$transaction(async (tx) => {
|
||||
@@ -87,7 +87,7 @@ export async function verifyTurnstileToken(
|
||||
const body = new URLSearchParams();
|
||||
body.set("secret", settings.turnstile.secretKey);
|
||||
body.set("response", token);
|
||||
body.set("remoteip", getClientIpFromHeaders());
|
||||
body.set("remoteip", await getClientIpFromHeaders());
|
||||
|
||||
const response = await fetch("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user