Files
100kmph_web/web/lib/auth.ts
T
2026-09-28 23:15:47 +05:30

12 lines
458 B
TypeScript

import { createHash, timingSafeEqual } from "crypto";
export function isAuthorized(header: string | null): boolean {
const expected = process.env.SYNC_TOKEN;
if (!expected || !header) return false;
const match = /^Bearer (\S+)$/.exec(header);
if (!match) return false;
const presented = createHash("sha256").update(match[1]).digest();
const actual = createHash("sha256").update(expected).digest();
return timingSafeEqual(presented, actual);
}