Validate hookdeck webhooks
This commit is contained in:
19
server/utils/hookdeck-validation.ts
Normal file
19
server/utils/hookdeck-validation.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { H3Event } from "h3";
|
||||
import { isEmpty } from "radash";
|
||||
|
||||
export const validateHookdeck = async (event: H3Event) => {
|
||||
const hookdeckKeyHeader = getHeader(event, "X-Hookdeck-Key");
|
||||
const config = useRuntimeConfig();
|
||||
|
||||
if (isEmpty(hookdeckKeyHeader)) {
|
||||
throw createError({
|
||||
status: 401,
|
||||
});
|
||||
}
|
||||
|
||||
if (hookdeckKeyHeader !== config.hookdeckKey) {
|
||||
throw createError({
|
||||
status: 401,
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user