Files
Checkmate/server/src/utils/utils.ts
T
Alex Holliday 3cf7243c93 summary
2026-01-20 18:56:06 +00:00

18 lines
602 B
TypeScript
Executable File

export const ParseBoolean = (value: boolean | string | null | undefined) => {
if (value === true || value === "true") {
return true;
} else if (value === false || value === "false" || value === null || value === undefined) {
return false;
}
};
export const getTokenFromHeaders = (headers: Record<string, string>) => {
const authorizationHeader = headers.authorization;
if (!authorizationHeader) throw new Error("No auth headers");
const parts = authorizationHeader.split(" ");
if (parts.length !== 2 || parts[0] !== "Bearer") throw new Error("Invalid auth headers");
return parts[1];
};