Skip to content

Commit 2762696

Browse files
committed
added page turnstile
1 parent 5382e03 commit 2762696

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

src/pages/AdminApps.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default function AdminApps() {
110110
{ key: 'totalRegistered', title: 'Users' },
111111
{ key: 'totalSessions', title: 'Sessions' },
112112
{ key: 'totalApiCalls', title: 'API' },
113-
// { key: 'totalTokens', title: 'AI' },
113+
{ key: 'totalTokens', title: 'AI' },
114114
{ key: 'totalFiles', title: 'Files' },
115115
{ key: 'totalTransactions', title: 'Transactions' },
116116
{ key: 'createdAt', title: 'Date' },

src/pages/TurnstileBridge.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { useEffect, useRef } from 'react';
2+
3+
const SITE_KEY = import.meta.env.VITE_TURNSTILE_SITE_KEY!;
4+
5+
declare global {
6+
interface Window {
7+
turnstile?: any;
8+
onTurnstileOK?: (token: string) => void;
9+
onTurnstileError?: (err: unknown) => void;
10+
}
11+
}
12+
13+
export default function TurnstileBridge() {
14+
const containerRef = useRef<HTMLDivElement | null>(null);
15+
16+
useEffect(() => {
17+
window.onTurnstileOK = (token: string) => {
18+
window.location.href =
19+
'ethoraappreactnative://turnstile?token=' + encodeURIComponent(token);
20+
};
21+
22+
window.onTurnstileError = (err: unknown) => {
23+
window.location.href =
24+
'ethoraappreactnative://turnstile?error=' +
25+
encodeURIComponent(String(err));
26+
};
27+
28+
const script = document.createElement('script');
29+
script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js';
30+
script.async = true;
31+
script.defer = true;
32+
script.onload = () => {
33+
if (containerRef.current && window.turnstile) {
34+
window.turnstile.render(containerRef.current, {
35+
sitekey: SITE_KEY,
36+
callback: 'onTurnstileOK',
37+
'error-callback': 'onTurnstileError',
38+
action: 'signup',
39+
theme: 'light',
40+
});
41+
}
42+
};
43+
document.head.appendChild(script);
44+
45+
return () => {
46+
document.head.removeChild(script);
47+
delete window.onTurnstileOK;
48+
delete window.onTurnstileError;
49+
};
50+
}, []);
51+
52+
return (
53+
<div
54+
style={{
55+
minHeight: '100vh',
56+
display: 'flex',
57+
alignItems: 'center',
58+
justifyContent: 'center',
59+
}}
60+
>
61+
<div ref={containerRef} />
62+
</div>
63+
);
64+
}

src/router.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const AppUsers = lazy(() => import('./pages/AppUsers'));
1717
const Profile = lazy(() => import('./pages/Profile'));
1818
const UserSettings = lazy(() => import('./pages/UserSettings/UserSettings'));
1919
const ProfileEdit = lazy(() => import('./pages/ProfileEdit'));
20+
const TurnstileBridge = lazy(() => import('./pages/TurnstileBridge'));
2021

2122
import App from './App';
2223
import AdminLayout from './pages/AdminLayout';
@@ -46,6 +47,10 @@ export const router = createBrowserRouter(
4647
path: '/resetPassword/:token?',
4748
Component: ForgetPassword,
4849
},
50+
{
51+
path: '/turnstile',
52+
Component: TurnstileBridge,
53+
},
4954
{
5055
path: '/app',
5156
element: <AppLayout />,

0 commit comments

Comments
 (0)