diff --git a/src/pages/api/v1/addTransaction.ts b/src/pages/api/v1/addTransaction.ts index ac70ebd0..f131b279 100644 --- a/src/pages/api/v1/addTransaction.ts +++ b/src/pages/api/v1/addTransaction.ts @@ -1,13 +1,16 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { db } from "@/server/db"; import { verifyJwt } from "@/lib/verifyJwt"; -import { cors } from "@/lib/cors"; +import { cors, addCorsCacheBustingHeaders } from "@/lib/cors"; import { getProvider } from "@/utils/get-provider"; export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { + // Add cache-busting headers for CORS + addCorsCacheBustingHeaders(res); + await cors(req, res); if (req.method === "OPTIONS") { return res.status(200).end(); diff --git a/src/pages/api/v1/authSigner.ts b/src/pages/api/v1/authSigner.ts index e7ffe355..8c5b6b7d 100644 --- a/src/pages/api/v1/authSigner.ts +++ b/src/pages/api/v1/authSigner.ts @@ -5,12 +5,15 @@ import { checkSignature, DataSignature, } from "@meshsdk/core"; -import { cors } from "@/lib/cors"; +import { cors, addCorsCacheBustingHeaders } from "@/lib/cors"; export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { + // Add cache-busting headers for CORS + addCorsCacheBustingHeaders(res); + await cors(req, res); if (req.method === "OPTIONS") { return res.status(200).end(); diff --git a/src/pages/api/v1/freeUtxos.ts b/src/pages/api/v1/freeUtxos.ts index 04770125..f619f81a 100644 --- a/src/pages/api/v1/freeUtxos.ts +++ b/src/pages/api/v1/freeUtxos.ts @@ -1,4 +1,4 @@ -import { cors } from "@/lib/cors"; +import { cors, addCorsCacheBustingHeaders } from "@/lib/cors"; //get all utxos for wallet //get all pending txs for the wallet //remove all wallet input utxos found in pending txs from the whole pool of txs. @@ -16,6 +16,9 @@ export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { + // Add cache-busting headers for CORS + addCorsCacheBustingHeaders(res); + await cors(req, res); if (req.method === "OPTIONS") { return res.status(200).end(); diff --git a/src/pages/api/v1/getNonce.ts b/src/pages/api/v1/getNonce.ts index a24d6c9b..e0e00214 100644 --- a/src/pages/api/v1/getNonce.ts +++ b/src/pages/api/v1/getNonce.ts @@ -1,42 +1,51 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { randomBytes } from "crypto"; import { db } from "@/server/db"; -import { cors } from "@/lib/cors"; +import { cors, addCorsCacheBustingHeaders } from "@/lib/cors"; export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { + // Add cache-busting headers for CORS + addCorsCacheBustingHeaders(res); + await cors(req, res); if (req.method === "OPTIONS") { return res.status(200).end(); } if (req.method === "GET") { - const { address } = req.query; - if (typeof address !== "string") { - return res.status(400).json({ error: "Invalid address" }); - } - // Verify that the address exists in the User table - const user = await db.user.findUnique({ where: { address } }); - if (!user) { - return res.status(404).json({ error: "Address not found" }); - } + try { + const { address } = req.query; + if (typeof address !== "string") { + return res.status(400).json({ error: "Invalid address" }); + } + + // Verify that the address exists in the User table + const user = await db.user.findUnique({ where: { address } }); + if (!user) { + return res.status(404).json({ error: "Address not found" }); + } - // Check if a nonce already exists for this address in the database - const existing = await db.nonce.findFirst({ where: { address } }); - if (existing) { - return res.status(200).json({ nonce: existing.value }); - } + // Check if a nonce already exists for this address in the database + const existing = await db.nonce.findFirst({ where: { address } }); + if (existing) { + return res.status(200).json({ nonce: existing.value }); + } - const nonce = randomBytes(16).toString("hex"); - await db.nonce.create({ - data: { - address, - value: nonce, - }, - }); - return res.status(200).json({ nonce }); + const nonce = randomBytes(16).toString("hex"); + await db.nonce.create({ + data: { + address, + value: nonce, + }, + }); + return res.status(200).json({ nonce }); + } catch (error) { + console.error("Error in getNonce:", error); + return res.status(500).json({ error: "Internal Server Error" }); + } } res.status(405).end(); diff --git a/src/pages/api/v1/lookupMultisigWallet.ts b/src/pages/api/v1/lookupMultisigWallet.ts index 66a52d1f..ac765866 100644 --- a/src/pages/api/v1/lookupMultisigWallet.ts +++ b/src/pages/api/v1/lookupMultisigWallet.ts @@ -1,11 +1,14 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { getProvider } from "@/utils/get-provider"; -import { cors } from "@/lib/cors"; +import { cors, addCorsCacheBustingHeaders } from "@/lib/cors"; export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { + // Add cache-busting headers for CORS + addCorsCacheBustingHeaders(res); + await cors(req, res); if (req.method === "OPTIONS") { return res.status(200).end(); diff --git a/src/pages/api/v1/nativeScript.ts b/src/pages/api/v1/nativeScript.ts index 807c52ec..fe0eb443 100644 --- a/src/pages/api/v1/nativeScript.ts +++ b/src/pages/api/v1/nativeScript.ts @@ -1,4 +1,4 @@ -import { cors } from "@/lib/cors"; +import { cors, addCorsCacheBustingHeaders } from "@/lib/cors"; import { NextApiRequest, NextApiResponse } from "next"; import { Wallet as DbWallet } from "@prisma/client"; import { buildMultisigWallet } from "@/utils/common"; @@ -10,6 +10,9 @@ export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { + // Add cache-busting headers for CORS + addCorsCacheBustingHeaders(res); + await cors(req, res); if (req.method === "OPTIONS") { return res.status(200).end(); diff --git a/src/pages/api/v1/submitDatum.ts b/src/pages/api/v1/submitDatum.ts index d13f3c4f..af37283d 100644 --- a/src/pages/api/v1/submitDatum.ts +++ b/src/pages/api/v1/submitDatum.ts @@ -1,7 +1,7 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { db } from "@/server/db"; import { verifyJwt } from "@/lib/verifyJwt"; -import { cors } from "@/lib/cors"; +import { cors, addCorsCacheBustingHeaders } from "@/lib/cors"; import { DataSignature } from "@meshsdk/core"; import { checkSignature } from "@meshsdk/core-cst"; @@ -9,6 +9,9 @@ export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { + // Add cache-busting headers for CORS + addCorsCacheBustingHeaders(res); + await cors(req, res); if (req.method === "OPTIONS") { return res.status(200).end();