From e164e4fdb073eedcc563fe84cda23b852dc41b39 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Thu, 22 Jan 2026 15:06:26 -0700 Subject: [PATCH] Add a exists check --- src/routes/get-verify-code.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/routes/get-verify-code.ts b/src/routes/get-verify-code.ts index 9448bb9..4284d61 100644 --- a/src/routes/get-verify-code.ts +++ b/src/routes/get-verify-code.ts @@ -8,6 +8,7 @@ import { } from '../lib/util' import { randomBytes } from 'crypto' import { verifyCodes } from '../lib/tables' +import { and, desc, eq, sql } from 'drizzle-orm' type Body = { token: string @@ -49,6 +50,29 @@ export async function handler (context: Context) { ) const { connection: connection0, db: db0 } = dbInfo0 + const codeExists = await db0 + .select({ code: verifyCodes.code }) + .from(verifyCodes) + .where( + and( + eq(verifyCodes.ip, ip), + eq(verifyCodes.used, false), + sql`${verifyCodes.timestamp} >= UNIX_TIMESTAMP() - 600` + ) + ) + .orderBy(desc(verifyCodes.id)) + .limit(1) + .execute() + if (codeExists[0]) + return jsonResponse( + { + success: true, + message: null, + data: codeExists[0].code + }, + 200 + ) + await db0.insert(verifyCodes).values({ code, ip, timestamp: time }) return jsonResponse(