Move webview captcha to api endpoint
This commit is contained in:
parent
036f532f31
commit
a9dec97e7f
@ -1,38 +0,0 @@
|
||||
import { useLoaderData } from "@remix-run/react";
|
||||
|
||||
export async function loader({
|
||||
context,
|
||||
}: {
|
||||
context: RequestContext;
|
||||
}): Promise<string> {
|
||||
return context.env.TURNSTILE_SITEKEY;
|
||||
}
|
||||
|
||||
export default function () {
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className="cf-turnstile"
|
||||
data-callback="returnToken"
|
||||
data-error-callback="handleError"
|
||||
data-sitekey={useLoaderData<typeof loader>()}
|
||||
></div>
|
||||
<script>
|
||||
{`
|
||||
function returnToken(token) {
|
||||
window.flutter_inappwebview.callHandler("onToken", token);
|
||||
}
|
||||
|
||||
function handleError(_error) {
|
||||
window.flutter_inappwebview.callHandler("onToken", null);
|
||||
}
|
||||
`}
|
||||
</script>
|
||||
<script
|
||||
async
|
||||
defer
|
||||
src="https://challenges.cloudflare.com/turnstile/v0/api.js"
|
||||
></script>
|
||||
</>
|
||||
);
|
||||
}
|
28
functions/api/webview-captcha.ts
Normal file
28
functions/api/webview-captcha.ts
Normal file
@ -0,0 +1,28 @@
|
||||
export async function onRequestGet(context: RequestContext) {
|
||||
return new Response(
|
||||
`<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>WebView Captcha</title>
|
||||
<script async defer src="https://challenges.cloudflare.com/turnstile/v0/api.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="cf-turnstile" data-callback="returnToken" data-error-callback="handleError" data-sitekey="${context.env.TURNSTILE_SITEKEY}"></div>
|
||||
<script>
|
||||
function handleError(_error) {
|
||||
window.flutter_inappwebview.callHandler("onToken", null);
|
||||
}
|
||||
|
||||
function returnToken(token) {
|
||||
window.flutter_inappwebview.callHandler("onToken", token);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>`,
|
||||
{
|
||||
headers: {
|
||||
"content-type": "text/html",
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user