Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/turnstile #649

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const appHono = new Hono();
appHono.use(
"/*",
cors({
origin: env.CORS_WEBSITE_URLS?.split(",") || ["http://localhost:3000", "http://localhost:3001"]
origin: env.CORS_WEBSITE_URLS?.split(",") || ["http://localhost:3000", "http://localhost:3001"],
credentials: true
})
);

Expand Down
3 changes: 2 additions & 1 deletion apps/deploy-web/.env.local.sample
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +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_SITE_KEY=0x4AAAAAAA5S2ADjyKnHmdzo
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
11 changes: 6 additions & 5 deletions apps/deploy-web/src/components/turnstile/Turnstile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import classnames from "classnames";

import { browserEnvConfig } from "@src/config/browser-env.config";

type TurnstileStatus = "uninitialized" | "solved" | "expired" | "error" | "dismissed";
type TurnstileStatus = "uninitialized" | "solved" | "interactive" | "expired" | "error" | "dismissed";

const VISIBILITY_STATUSES: TurnstileStatus[] = ["uninitialized", "expired", "error"];
const VISIBILITY_STATUSES: TurnstileStatus[] = ["uninitialized", "interactive", "error"];

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 (
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 All @@ -42,6 +42,7 @@ export const Turnstile: FC = () => {
onError={() => setStatus("error")}
onExpire={() => setStatus("expired")}
onSuccess={() => setStatus("solved")}
onBeforeInteractive={() => setStatus("interactive")}
/>
</div>
{status === "error" && <p className="text-red-600">Some error occurred</p>}
Expand Down Expand Up @@ -71,5 +72,5 @@ export const Turnstile: FC = () => {
</div>
</div>
</>
);
) : null;
};
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
});
1 change: 1 addition & 0 deletions apps/deploy-web/src/config/env-config.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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_ENABLED: coercedBoolean(),
NEXT_PUBLIC_TURNSTILE_SITE_KEY: z.string()
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ApiWalletOutput {

export class ManagedWalletHttpService extends ApiHttpService {
async createWallet(userId: string) {
return this.addWalletEssentials(this.extractApiData(await this.post<ApiWalletOutput>("v1/start-trial", { data: { userId } })));
return this.addWalletEssentials(this.extractApiData(await this.post<ApiWalletOutput>("v1/start-trial", { data: { userId } }, { withCredentials: true })));
}

async getWallet(userId: string) {
Expand Down
Loading