Skip to content

Commit 89a6e1c

Browse files
committed
[Dashboard] Improve faucet claim
1 parent 519349b commit 89a6e1c

File tree

1 file changed

+16
-1
lines changed
  • apps/dashboard/src/app/api/testnet-faucet/claim

1 file changed

+16
-1
lines changed

apps/dashboard/src/app/api/testnet-faucet/claim/route.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
12
import { startOfToday } from "date-fns";
23
import { cacheGet, cacheSet } from "lib/redis";
34
import { type NextRequest, NextResponse } from "next/server";
4-
import { ZERO_ADDRESS } from "thirdweb";
5+
import { ZERO_ADDRESS, getAddress } from "thirdweb";
56
import { getFaucetClaimAmount } from "./claim-amount";
67

78
const THIRDWEB_ENGINE_URL = process.env.THIRDWEB_ENGINE_URL;
@@ -19,6 +20,20 @@ interface RequestTestnetFundsPayload {
1920

2021
// Note: This handler cannot use "edge" runtime because of Redis usage.
2122
export const POST = async (req: NextRequest) => {
23+
// Make sure user's connected to the site
24+
const activeAccount = req.cookies.get(COOKIE_ACTIVE_ACCOUNT)?.value;
25+
const authCookie = activeAccount
26+
? req.cookies.get(COOKIE_PREFIX_TOKEN + getAddress(activeAccount))
27+
: null;
28+
if (!authCookie) {
29+
return NextResponse.json(
30+
{
31+
error: "No wallet connected",
32+
},
33+
{ status: 400 },
34+
);
35+
}
36+
2237
const requestBody = (await req.json()) as RequestTestnetFundsPayload;
2338
const { chainId, toAddress, turnstileToken } = requestBody;
2439
if (Number.isNaN(chainId)) {

0 commit comments

Comments
 (0)