feat: Add register + hcaptcha

This commit is contained in:
mrjvs
2026-08-09 20:03:41 +02:00
parent f73a02fb57
commit bf4ab24043
9 changed files with 82 additions and 7 deletions

14
server/utils/hcaptcha.ts Normal file
View File

@@ -0,0 +1,14 @@
import type { H3Event } from 'h3'
import hcaptcha from 'hcaptcha'
export async function hcaptchaVerify(event: H3Event, captchaResponse: string | null | undefined): Promise<boolean> {
const config = useRuntimeConfig(event);
if (!config.hcaptchaSiteKey) return true; // No captcha is configured, always valid
if (!config.hcaptchaSecretKey) throw new Error("Hcaptcha not configured correctly, missing secret key");
if (!captchaResponse) return false; // No captcha filled in, invalid
const captchaVerify = await hcaptcha.verify(config.hcaptchaSiteKey, captchaResponse, undefined, config.hcaptchaSiteKey);
if (!captchaVerify.success) return false; // Invalid captcha response
return true;
}