Skip to content

Commit

Permalink
refactor(auth): use explicit turnstile env var toggle
Browse files Browse the repository at this point in the history
refs #627
  • Loading branch information
ygrishajev committed Jan 16, 2025
1 parent c64d15e commit 99ac4f2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/deploy-web/.env.local.sample
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ BASE_API_SANDBOX_URL=http://${BASE_API_MAINNET_URL}:3080
GITHUB_CLIENT_SECRET=GITHUB_CLIENT_SECRET
BITBUCKET_CLIENT_SECRET=BITBUCKET_CLIENT_SECRET
GITLAB_CLIENT_SECRET=GITLAB_CLIENT_SECRET
NEXT_PUBLIC_TURNSTILE_ENABLED=false
NEXT_PUBLIC_TURNSTILE_SITE_KEY=0x4AAAAAAA5S2ADjyKnHmdzo
1 change: 1 addition & 0 deletions apps/deploy-web/env/.env.production
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
AUTH0_BASE_URL=https://console.akash.network
AUTH0_ISSUER_BASE_URL=https://auth.cloudmos.io

NEXT_PUBLIC_TURNSTILE_ENABLED=true
NEXT_PUBLIC_TURNSTILE_SITE_KEY=0x4AAAAAAA5Stdp3_0Q5FClX

NEXT_PUBLIC_DEFAULT_NETWORK_ID=mainnet
Expand Down
1 change: 1 addition & 0 deletions apps/deploy-web/env/.env.staging
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
AUTH0_BASE_URL=https://console-beta.akash.network
AUTH0_ISSUER_BASE_URL=https://dev-5aprb0lr.us.auth0.com

NEXT_PUBLIC_TURNSTILE_ENABLED=true
NEXT_PUBLIC_TURNSTILE_SITE_KEY=0x4AAAAAAA5Stdp3_0Q5FClX

NEXT_PUBLIC_DEFAULT_NETWORK_ID=mainnet
Expand Down
4 changes: 2 additions & 2 deletions apps/deploy-web/src/components/turnstile/Turnstile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const Turnstile: FC = () => {
const turnstileRef = useRef<TurnstileInstance>();
const [status, setStatus] = useState<TurnstileStatus>("uninitialized");
const [isTimingOut, setIsTimingOut] = useState(false);
const isVisible = useMemo(() => !!browserEnvConfig.NEXT_PUBLIC_TURNSTILE_SITE_KEY && VISIBILITY_STATUSES.includes(status), [status]);
const isVisible = useMemo(() => !!browserEnvConfig.NEXT_PUBLIC_TURNSTILE_ENABLED && VISIBILITY_STATUSES.includes(status), [status]);
const hasActions = useMemo(() => isTimingOut || status === "error", [isTimingOut, status]);

useEffect(() => {
Expand All @@ -29,7 +29,7 @@ export const Turnstile: FC = () => {
}
}, [isVisible]);

return browserEnvConfig.NEXT_PUBLIC_TURNSTILE_SITE_KEY ? (
return browserEnvConfig.NEXT_PUBLIC_TURNSTILE_ENABLED ? (
<>
<div className={classnames({ hidden: !isVisible }, "fixed inset-0 z-[101] flex content-center items-center justify-center bg-white bg-opacity-90")}>
<div className="flex flex-col items-center">
Expand Down
1 change: 1 addition & 0 deletions apps/deploy-web/src/config/browser-env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export const browserEnvConfig = validateStaticEnvVars({
NEXT_PUBLIC_GITHUB_CLIENT_ID: process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID,
NEXT_PUBLIC_GA_MEASUREMENT_ID: process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID,
NEXT_PUBLIC_CI_CD_IMAGE_NAME: process.env.NEXT_PUBLIC_CI_CD_IMAGE_NAME,
NEXT_PUBLIC_TURNSTILE_ENABLED: process.env.NEXT_PUBLIC_TURNSTILE_ENABLED,
NEXT_PUBLIC_TURNSTILE_SITE_KEY: process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY
});
3 changes: 2 additions & 1 deletion apps/deploy-web/src/config/env-config.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const browserEnvSchema = z.object({
NEXT_PUBLIC_GITLAB_CLIENT_ID: z.string().optional(),
NEXT_PUBLIC_GITHUB_CLIENT_ID: z.string().optional(),
NEXT_PUBLIC_CI_CD_IMAGE_NAME: z.string(),
NEXT_PUBLIC_TURNSTILE_SITE_KEY: z.string().optional()
NEXT_PUBLIC_TURNSTILE_ENABLED: coercedBoolean(),
NEXT_PUBLIC_TURNSTILE_SITE_KEY: z.string()
});

export const serverEnvSchema = browserEnvSchema.extend({
Expand Down

0 comments on commit 99ac4f2

Please sign in to comment.