-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add captcha validation on session creation
- Loading branch information
Showing
7 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const CLOUDFLARE_CAPTCHA_URL = | ||
"https://challenges.cloudflare.com/turnstile/v0/siteverify"; | ||
|
||
export const isCaptchaValid = async (token: string) => { | ||
if (import.meta.env.CAPTCHA_ENABLED === "false") return true; | ||
if (!import.meta.env.PUBLIC_TURNSTILE_SECRET_KEY) return true; | ||
try { | ||
const response = await fetch(CLOUDFLARE_CAPTCHA_URL, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}, | ||
body: JSON.stringify({ | ||
secret: import.meta.env.PUBLIC_TURNSTILE_SECRET_KEY, | ||
response: token | ||
}) | ||
}); | ||
|
||
const data = await response.json(); | ||
return data.success; | ||
} catch (error) { | ||
console.error("Error validating captcha:", error); | ||
return false; | ||
} | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.