Skip to content

Commit 8ebf72d

Browse files
committed
register fix
1 parent 5113e72 commit 8ebf72d

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
run: npm ci
3737

3838
- name: Build site
39+
env:
40+
VITE_TURNSTILE_SITE_KEY: ${{ vars.VITE_TURNSTILE_SITE_KEY }}
3941
run: npm run build
4042

4143
- name: Upload Pages artifact

src/env.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
/// <reference types="vite/client" />
2+
13
interface ImportMetaEnv {
24
readonly VITE_ADMIN_IDLE_TIMEOUT_MINUTES?: string;
5+
readonly VITE_TURNSTILE_SITE_KEY?: string;
36
readonly VITE_STRIPE_PUBLISHABLE_KEY?: string;
47
readonly VITE_STRIPE_PRICING_TABLE_ID?: string;
58
readonly VITE_STRIPE_API_BASE_URL?: string;

src/pages/auth/Register.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { formatPhoneNumber, normalizePhoneNumber } from "../../utils/phoneNumber
1212
import { evaluatePasswordStrength } from "../../utils/passwordSecurity";
1313
import "./Register.css";
1414

15+
const TURNSTILE_TEST_SITE_KEY = "1x00000000000000000000AA";
16+
1517
export default function Register() {
1618
const [displayName, setDisplayName] = useState("");
1719
const [email, setEmail] = useState("");
@@ -29,7 +31,8 @@ export default function Register() {
2931
const navigate = useNavigate();
3032
const location = useLocation();
3133
const from = (location.state as { from?: string })?.from || "/";
32-
const turnstileSiteKey = import.meta.env.VITE_TURNSTILE_SITE_KEY?.trim() ?? "";
34+
const configuredTurnstileSiteKey = import.meta.env.VITE_TURNSTILE_SITE_KEY?.trim() ?? "";
35+
const turnstileSiteKey = configuredTurnstileSiteKey || (import.meta.env.DEV ? TURNSTILE_TEST_SITE_KEY : "");
3336

3437
const displayError = localError || authError;
3538
const passwordStrength = useMemo(() => evaluatePasswordStrength(password), [password]);
@@ -61,6 +64,7 @@ export default function Register() {
6164
const toggleConfirmLabel = showConfirmPassword ? "Hide confirm password" : "Show confirm password";
6265
const isTurnstileReady = Boolean(turnstileSiteKey);
6366
const isTurnstileVerified = Boolean(turnstileToken);
67+
const usingTurnstileTestKey = !configuredTurnstileSiteKey && turnstileSiteKey === TURNSTILE_TEST_SITE_KEY;
6468

6569
const handleTurnstileSuccess = useCallback((token: string) => {
6670
setTurnstileToken(token);
@@ -107,7 +111,7 @@ export default function Register() {
107111
}
108112

109113
if (!isTurnstileReady) {
110-
setLocalError("Turnstile site key missing. Add VITE_TURNSTILE_SITE_KEY to your .env file.");
114+
setLocalError("Turnstile site key missing. Add VITE_TURNSTILE_SITE_KEY to your environment configuration.");
111115
return;
112116
}
113117

@@ -277,15 +281,23 @@ export default function Register() {
277281
</p>
278282

279283
{isTurnstileReady ? (
280-
<TurnstileWidget
281-
siteKey={turnstileSiteKey}
282-
onSuccess={handleTurnstileSuccess}
283-
onExpire={handleTurnstileExpire}
284-
onError={handleTurnstileError}
285-
/>
284+
<>
285+
<TurnstileWidget
286+
siteKey={turnstileSiteKey}
287+
onSuccess={handleTurnstileSuccess}
288+
onExpire={handleTurnstileExpire}
289+
onError={handleTurnstileError}
290+
/>
291+
{usingTurnstileTestKey ? (
292+
<p className="auth-turnstile-missing">
293+
Using Cloudflare&apos;s test Turnstile key for local development. Add{" "}
294+
<code>VITE_TURNSTILE_SITE_KEY</code> to your environment configuration before deploying.
295+
</p>
296+
) : null}
297+
</>
286298
) : (
287299
<p className="auth-turnstile-missing">
288-
Turnstile is not configured yet. Add <code>VITE_TURNSTILE_SITE_KEY</code> to your <code>.env</code> file.
300+
Turnstile is not configured yet. Add <code>VITE_TURNSTILE_SITE_KEY</code> to your environment configuration.
289301
</p>
290302
)}
291303

0 commit comments

Comments
 (0)