From 4b866891ac3c6a18051ffc1e35ee78c567feb810 Mon Sep 17 00:00:00 2001 From: HeesungB Date: Thu, 8 Dec 2022 23:31:51 +0900 Subject: [PATCH] Change to real user twitter information from dummy --- pages/api/twitter-auth-info.ts | 35 +++++++++++++++++++---- pages/verification/index.tsx | 52 ++++++++++++++++++---------------- types/api-response.ts | 6 ++++ 3 files changed, 63 insertions(+), 30 deletions(-) diff --git a/pages/api/twitter-auth-info.ts b/pages/api/twitter-auth-info.ts index ca75901..f2bf18d 100644 --- a/pages/api/twitter-auth-info.ts +++ b/pages/api/twitter-auth-info.ts @@ -63,16 +63,31 @@ export default withIronSessionApiRoute(async function handler( req.session.refresh_token = refresh_token; await req.session.save(); const { - data: { id, username }, - } = await request(`${twitterApiBaseUrl}/users/me`, { - headers: { - Authorization: `Bearer ${accessToken}`, + data: { + id, + username, + name, + profile_image_url, + description, + public_metrics, }, - }); + } = await request( + `${twitterApiBaseUrl}/users/me?user.fields=profile_image_url,public_metrics,description`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }, + ); + res.status(200).json({ accessToken, id, username, + name, + profile_image_url: profile_image_url.replace("normal.jpg", "400x400.jpg"), + description, + public_metrics, }); } catch (error) { console.error(error); @@ -94,5 +109,15 @@ interface TwitterUsersMeResponse { id: string; username: string; name: string; + profile_image_url: string; + description: string; + public_metrics: TwitterPublicMetrics; }; } + +export interface TwitterPublicMetrics { + followers_count: number; + following_count: number; + listed_count: number; + tweet_count: number; +} diff --git a/pages/verification/index.tsx b/pages/verification/index.tsx index 27698cb..1e0f776 100644 --- a/pages/verification/index.tsx +++ b/pages/verification/index.tsx @@ -34,10 +34,6 @@ export default function VerificationPage() { const [isLoading, setIsLoading] = useState(true); - useEffect(() => { - setTimeout(() => setIsLoading(false), 1500); - }, []); - useEffect(() => { const handleVerification = async () => { if (window.location.search) { @@ -50,9 +46,8 @@ export default function VerificationPage() { `/api/twitter-auth-info?state=${state}&code=${code}`, ); - console.log(newTwitterAuthInfo); - setTwitterAuthInfo(newTwitterAuthInfo); + const verifierMsg: VerifierMsg = { unique_twitter_id: newTwitterAuthInfo.id, name: newTwitterAuthInfo.username, @@ -60,20 +55,19 @@ export default function VerificationPage() { contract_address: "osmo1y5mm5nj5m8ttddt5ccspek6xgyyavehrkak7gq", chain_id: "osmosis-1", }; - const icnsVerification = await request( - "/api/icns-verification", - { - method: "post", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - msg: JSON.stringify(verifierMsg), - authToken: newTwitterAuthInfo.accessToken, - }), + + await request("/api/icns-verification", { + method: "post", + headers: { + "Content-Type": "application/json", }, - ); - console.log(icnsVerification); + body: JSON.stringify({ + msg: JSON.stringify(verifierMsg), + authToken: newTwitterAuthInfo.accessToken, + }), + }); + + setIsLoading(false); } }; @@ -182,30 +176,38 @@ export default function VerificationPage() { profile image - BaeHeesung + + {twitterAuthInfo?.name} + - @BaeHeesung25 + {twitterAuthInfo?.username} - 42 Following + + {twitterAuthInfo?.public_metrics?.following_count} + {" "} + Following - 42 Following + + {twitterAuthInfo?.public_metrics?.followers_count} + {" "} + Followers - Product UIUX designer @Keplrwallet and I like @regen_network🌿 + {twitterAuthInfo?.description} diff --git a/types/api-response.ts b/types/api-response.ts index 9992681..1292bf7 100644 --- a/types/api-response.ts +++ b/types/api-response.ts @@ -1,3 +1,5 @@ +import { TwitterPublicMetrics } from "../pages/api/twitter-auth-info"; + export interface TwitterAuthUrlResponse { authUrl: string; } @@ -5,7 +7,11 @@ export interface TwitterAuthUrlResponse { export interface TwitterAuthInfoResponse { accessToken: string; id: string; + name: string; username: string; + profile_image_url: string; + description: string; + public_metrics: TwitterPublicMetrics; } export interface IcnsVerificationResponse {