diff --git a/pages/api/icns-verification.ts b/pages/api/icns-verification.ts index 60cd817..47b46fe 100644 --- a/pages/api/icns-verification.ts +++ b/pages/api/icns-verification.ts @@ -9,21 +9,29 @@ export default withIronSessionApiRoute(async function handler( res: NextApiResponse, ) { try { - if (!process.env.ICNS_VERIFIER_URI) { + if (!process.env.ICNS_VERIFIER_ORIGIN_LIST) { console.log(".env is not set"); return res.status(500).json({ error: "Internal server error" }); } - const icnsVerificationInfo = await request( - process.env.ICNS_VERIFIER_URI, - { - method: "post", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(req.body), - }, + const verifierOriginList = process.env.ICNS_VERIFIER_ORIGIN_LIST.split(","); + + const verificationList = await Promise.allSettled( + verifierOriginList.map((verfierOrigin) => + request( + `${verfierOrigin}/api/verify_twitter`, + { + method: "post", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(req.body), + }, + ), + ), ); - res.status(200).json(icnsVerificationInfo); + res.status(200).json({ + verificationList, + }); } catch (error) { console.error(error); res.status(500).json({ error: "Internal server error" }); diff --git a/pages/verification/index.tsx b/pages/verification/index.tsx index 1e0f776..921a9b1 100644 --- a/pages/verification/index.tsx +++ b/pages/verification/index.tsx @@ -8,7 +8,7 @@ import Image from "next/image"; import { IcnsVerificationResponse, TwitterAuthInfoResponse, - VerifierMsg, + VerifyingMsg, WidthHeightProps, } from "../../types"; import { request } from "../../utils/url"; @@ -48,24 +48,20 @@ export default function VerificationPage() { setTwitterAuthInfo(newTwitterAuthInfo); - const verifierMsg: VerifierMsg = { - unique_twitter_id: newTwitterAuthInfo.id, - name: newTwitterAuthInfo.username, - claimer: "osmo1y5mm5nj5m8ttddt5ccspek6xgyyavehrkak7gq", - contract_address: "osmo1y5mm5nj5m8ttddt5ccspek6xgyyavehrkak7gq", - chain_id: "osmosis-1", - }; + const icnsVerificationList = ( + await request("/api/icns-verification", { + method: "post", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + claimer: "osmo1y5mm5nj5m8ttddt5ccspek6xgyyavehrkak7gq", + authToken: newTwitterAuthInfo.accessToken, + }), + }) + ).verificationList; - await request("/api/icns-verification", { - method: "post", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - msg: JSON.stringify(verifierMsg), - authToken: newTwitterAuthInfo.accessToken, - }), - }); + console.log(icnsVerificationList); setIsLoading(false); } diff --git a/types/api-response.ts b/types/api-response.ts index 1292bf7..063453f 100644 --- a/types/api-response.ts +++ b/types/api-response.ts @@ -15,6 +15,21 @@ export interface TwitterAuthInfoResponse { } export interface IcnsVerificationResponse { - signature: number[]; - algorithm: string; + verificationList: ( + | { + status: "fulfilled"; + value: { + errors: Error[]; + data: { + verifying_msg: string; + signature: number[]; + algorithm: string; + }; + }; + } + | { + status: "rejected"; + reason: Error; + } + )[]; } diff --git a/types/msg.ts b/types/msg.ts index 9a3da09..8246286 100644 --- a/types/msg.ts +++ b/types/msg.ts @@ -1,4 +1,4 @@ -export interface VerifierMsg { +export interface VerifyingMsg { unique_twitter_id: string; name: string; claimer: string;