mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2025-12-31 14:49:36 -06:00
31 lines
703 B
JavaScript
Executable File
31 lines
703 B
JavaScript
Executable File
/**
|
|
* Converts a request body parameter to a boolean.
|
|
* @param {string | boolean} value
|
|
* @returns {boolean}
|
|
*/
|
|
const ParseBoolean = (value) => {
|
|
if (value === true || value === "true") {
|
|
return true;
|
|
} else if (
|
|
value === false ||
|
|
value === "false" ||
|
|
value === null ||
|
|
value === undefined
|
|
) {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
const getTokenFromHeaders = (headers) => {
|
|
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];
|
|
};
|
|
|
|
export { ParseBoolean, getTokenFromHeaders };
|