icns-frontend/queries/twitter.ts

45 lines
1014 B
TypeScript
Raw Normal View History

2022-12-15 06:02:50 +00:00
import {
2022-12-23 13:30:35 +00:00
IcnsVerificationResponseOnFrontend,
2022-12-15 06:02:50 +00:00
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 (
2022-12-23 13:30:35 +00:00
await request<IcnsVerificationResponseOnFrontend>(
"/api/icns-verification",
{
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
claimer: claimer,
authToken: accessToken,
}),
2022-12-15 06:02:50 +00:00
},
2022-12-23 13:30:35 +00:00
)
2022-12-15 06:02:50 +00:00
).verificationList;
2022-12-14 07:52:05 +00:00
};