Update management-auth.ts
CI / ci (push) Canceled after 0s

This commit is contained in:
Stefan Lazic committed 2026-09-04 22:55:53 +01:00
1 parent ac9791c8ef
commit a65360b82d
1 file changed
+20 -2
+20 -2
View File
@@ -48,14 +48,32 @@ export async function clearManagerSession() {
export async function isManagerAuthenticated() { export async function isManagerAuthenticated() {
const config = getManagerConfig(); const config = getManagerConfig();
console.log("[manager-auth] auth secret:", config.authSecret ? "set" : "missing");
if (!config.authSecret) return false; if (!config.authSecret) return false;
const rawValue = (await cookies()).get(COOKIE_NAME)?.value;
const cookieStore = await cookies();
const rawValue = cookieStore.get(COOKIE_NAME)?.value;
console.log("[manager-auth] cookie:", rawValue ? "received" : "missing");
const value = rawValue ? decodeURIComponent(rawValue) : undefined; const value = rawValue ? decodeURIComponent(rawValue) : undefined;
if (!value) return false; if (!value) return false;
const separator = value.lastIndexOf("."); const separator = value.lastIndexOf(".");
if (separator < 1) return false; if (separator < 1) return false;
const payload = value.slice(0, separator); const payload = value.slice(0, separator);
const received = Buffer.from(value.slice(separator + 1)); const received = Buffer.from(value.slice(separator + 1));
const expected = Buffer.from(signature(payload, config.authSecret)); const expected = Buffer.from(signature(payload, config.authSecret));
return received.length === expected.length && timingSafeEqual(received, expected);
const valid =
received.length === expected.length &&
timingSafeEqual(received, expected);
console.log("[manager-auth] signature valid:", valid);
return valid;
} }