Skip to content

Commit

Permalink
clean up rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Primata committed Aug 6, 2024
1 parent 6e2952b commit 9c44aa1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 10 deletions.
8 changes: 0 additions & 8 deletions api/rate-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,13 @@ async function createAssessment(

export default async function handler(request: any, response: any) {
// You could alternatively limit based on user ID or similar
console.log("init verification");
const {token, address} = request.body;
console.log("token", token);
console.log("address", address);
const secretKey = process.env.RECAPTCHA_SECRET_KEY;
const verificationUrl = `https://www.google.com/recaptcha/api/siteverify?secret=${secretKey}&response=${token}`;

if (!secretKey) {
return request.status(500).json({error: "reCAPTCHA secret key not set"});
}
console.log("secret key exists");
const ip = ips(request) ?? "127.0.0.1";

const {success, pending, limit, reset, remaining} = await ratelimit.limit(
Expand All @@ -115,18 +111,14 @@ export default async function handler(request: any, response: any) {
method: "POST",
});
const data = await verification.json();
console.log("data", data);
if (data.success == false) {
return response
.status(400)
.json({success: false, error: "Invalid reCAPTCHA token"});
}
console.log("verification successful", data.success);
console.log("not rate limited", success);
if (!success) {
return response.status(429).json({success: false, error: "Rate limited"});
}
// TODO: Move faucet request here
const aptos = new Aptos(
new AptosConfig({
fullnode: "https://aptos.testnet.suzuka.movementlabs.xyz/v1",
Expand Down
3 changes: 1 addition & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AptosAccount, AptosClient, FaucetClient, Types, CoinClient } from "aptos";
import { Aptos } from "@aptos-labs/ts-sdk"
import { AptosClient, Types } from "aptos";
import { OCTA } from "../constants";
import { isNumeric } from "../pages/utils";
import { sortTransactions } from "../utils";
Expand Down

0 comments on commit 9c44aa1

Please sign in to comment.