icns-frontend/queries/twitter.ts

42 lines
957 B
TypeScript
Raw Normal View History

2022-12-15 06:02:50 +00:00
import {
IcnsVerificationResponse,
TwitterAuthInfoResponse,
TwitterAuthUrlResponse,
} from "../types";
2022-12-14 07:52:05 +00:00
import { request } from "../utils/url";
export const loginWithTwitter = async () => {
2022-12-15 10:06:44 +00:00
const { authUrl } = await request<TwitterAuthUrlResponse>(
"/api/twitter-auth-url",
);
2022-12-14 07:52:05 +00:00
window.location.href = authUrl;
};
export const fetchTwitterInfo = async (
state: string,
code: string,
): Promise<TwitterAuthInfoResponse> => {
2022-12-15 06:02:50 +00:00
return await request<TwitterAuthInfoResponse>(
2022-12-14 07:52:05 +00:00
`/api/twitter-auth-info?state=${state}&code=${code}`,
);
2022-12-15 06:02:50 +00:00
};
2022-12-14 07:52:05 +00:00
2022-12-15 06:02:50 +00:00
export const verifyTwitterAccount = async (
claimer: string,
accessToken: string,
) => {
return (
await request<IcnsVerificationResponse>("/api/icns-verification", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
claimer: claimer,
authToken: accessToken,
}),
})
).verificationList;
2022-12-14 07:52:05 +00:00
};