1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-20 14:37:43 +01:00

Trying to fix turnstile

This commit is contained in:
Vikas Kapadiya 2024-06-08 11:44:47 +05:30
parent c2c37b9c52
commit 5da2161bb9
4 changed files with 5247 additions and 4275 deletions

View file

@ -67,7 +67,6 @@
"react-lazy-with-preload": "^2.2.1", "react-lazy-with-preload": "^2.2.1",
"react-router-dom": "^6.23.0", "react-router-dom": "^6.23.0",
"react-sticky-el": "^2.1.0", "react-sticky-el": "^2.1.0",
"react-turnstile": "^1.1.3",
"react-use": "^17.5.0", "react-use": "^17.5.0",
"semver": "^7.6.0", "semver": "^7.6.0",
"slugify": "^1.6.6", "slugify": "^1.6.6",

File diff suppressed because it is too large Load diff

View file

@ -176,7 +176,6 @@ const root = createRoot(container!);
root.render( root.render(
<StrictMode> <StrictMode>
<ErrorBoundary> <ErrorBoundary>
<TurnstileProvider />
<HelmetProvider> <HelmetProvider>
<Suspense fallback={<LoadingScreen type="lazy" />}> <Suspense fallback={<LoadingScreen type="lazy" />}>
<ExtensionStatus /> <ExtensionStatus />

View file

@ -76,11 +76,6 @@ export function isTurnstileInitialized() {
export async function getTurnstileToken() { export async function getTurnstileToken() {
const turnstile = getTurnstile(); const turnstile = getTurnstile();
try { try {
// I hate turnstile
(window as any).turnstile.execute(
document.querySelector(`#${turnstile.id}`),
{},
);
const token = await useTurnstileStore.getState().getToken(); const token = await useTurnstileStore.getState().getToken();
reportCaptchaSolve(true); reportCaptchaSolve(true);
return token; return token;
@ -99,7 +94,6 @@ export function TurnstileProvider(props: {
const setTurnstile = useTurnstileStore((s) => s.setTurnstile); const setTurnstile = useTurnstileStore((s) => s.setTurnstile);
const processToken = useTurnstileStore((s) => s.processToken); const processToken = useTurnstileStore((s) => s.processToken);
if (!siteKey) return null; if (!siteKey) return null;
const widgetId = idRef.current || "sudo-turnstile";
return ( return (
<div <div
className={classNames({ className={classNames({
@ -109,19 +103,20 @@ export function TurnstileProvider(props: {
<Turnstile <Turnstile
siteKey={siteKey} siteKey={siteKey}
options={{ options={{
refreshExpired: "never", refreshExpired: "auto",
theme: "light", theme: "light",
}} }}
onLoadScript={() => { onWidgetLoad={(widgetId) => {
idRef.current = widgetId;
setTurnstile(widgetId, "sudo", !!props.isInPopout); setTurnstile(widgetId, "sudo", !!props.isInPopout);
}} }}
onError={() => { onError={() => {
const id = "sudo-turnstile"; const id = idRef.current;
if (!id) return; if (!id) return;
processToken(null, id); processToken(null, id);
}} }}
onSuccess={(token) => { onSuccess={(token) => {
const id = "sudo-turnstile"; const id = idRef.current;
if (!id) return; if (!id) return;
processToken(token, id); processToken(token, id);
props.onUpdateShow?.(false); props.onUpdateShow?.(false);