1 file changed
+2
-20
@@ -48,32 +48,14 @@ 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;
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user