1 file changed
+20
-2
@@ -48,14 +48,32 @@ export async function clearManagerSession() {
|
||||
|
||||
export async function isManagerAuthenticated() {
|
||||
const config = getManagerConfig();
|
||||
|
||||
console.log("[manager-auth] auth secret:", config.authSecret ? "set" : "missing");
|
||||
|
||||
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;
|
||||
|
||||
if (!value) return false;
|
||||
|
||||
const separator = value.lastIndexOf(".");
|
||||
if (separator < 1) return false;
|
||||
|
||||
const payload = value.slice(0, separator);
|
||||
const received = Buffer.from(value.slice(separator + 1));
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user