diff --git a/app/api/wallet-set/route.ts b/app/api/wallet-set/route.ts index db8465b..da238c4 100644 --- a/app/api/wallet-set/route.ts +++ b/app/api/wallet-set/route.ts @@ -18,9 +18,19 @@ import { NextRequest, NextResponse } from "next/server"; import { circleDeveloperSdk } from "@/lib/circle/developer-controlled-wallets-client"; +import { createClient } from "@/lib/supabase/server"; export async function POST(req: NextRequest) { try { + const supabase = await createClient(); + const { + data: { user }, + } = await supabase.auth.getUser(); + + if (!user) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + const { entityName } = await req.json(); if (!entityName.trim()) { diff --git a/app/api/wallet/route.ts b/app/api/wallet/route.ts index f65aaf6..aaea349 100644 --- a/app/api/wallet/route.ts +++ b/app/api/wallet/route.ts @@ -33,6 +33,15 @@ const DB_CHAIN_TO_SDK: Record = { export async function POST(req: NextRequest) { try { + const supabase = await createClient(); + const { + data: { user }, + } = await supabase.auth.getUser(); + + if (!user) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + const { walletSetId, blockchain } = await req.json(); if (!walletSetId || !blockchain) { @@ -63,31 +72,24 @@ export async function POST(req: NextRequest) { // After creating the wallet, register the gateway signer try { - const supabase = await createClient(); - const { - data: { user }, - } = await supabase.auth.getUser(); - - if (user) { - const { data: eoaWallet } = await supabase - .from("wallets") - .select("address") - .eq("user_id", user.id) - .eq("blockchain", blockchain) - .eq("type", "gateway_signer") - .single(); + const { data: eoaWallet } = await supabase + .from("wallets") + .select("address") + .eq("user_id", user.id) + .eq("blockchain", blockchain) + .eq("type", "gateway_signer") + .single(); - if (eoaWallet) { - console.log( - `Will add EOA delegate ${eoaWallet.address} for depositor ${response.data.wallets[0].address}` - ); - await initiateDepositFromCustodialWallet( - response.data.wallets[0].id as string, - DB_CHAIN_TO_SDK[blockchain], - BigInt(0), - eoaWallet.address as any - ); - } + if (eoaWallet) { + console.log( + `Will add EOA delegate ${eoaWallet.address} for depositor ${response.data.wallets[0].address}` + ); + await initiateDepositFromCustodialWallet( + response.data.wallets[0].id as string, + DB_CHAIN_TO_SDK[blockchain], + BigInt(0), + eoaWallet.address as any + ); } } catch (error) { console.error("Failed to register delegate for gateway:", error);