icns-frontend/pages/verification/index.tsx

30 lines
746 B
TypeScript
Raw Normal View History

2022-12-01 08:33:51 +00:00
import { useEffect, useState } from "react";
2022-12-05 11:01:24 +00:00
import { TwitterAuthInfoResponse } from "../../types/api-response";
2022-12-01 08:33:51 +00:00
export default function VerificationPage() {
const [accessToken, setAccessToken] = useState<string>();
const fetchAccessToken = async (state: string, code: string) => {
2022-12-05 11:01:24 +00:00
const { accessToken }: TwitterAuthInfoResponse = await (
2022-12-01 08:33:51 +00:00
await fetch(`/api/auth/access-token?state=${state}&code=${code}`)
).json();
2022-12-05 10:50:13 +00:00
setAccessToken(accessToken);
2022-12-01 08:33:51 +00:00
};
useEffect(() => {
const [, state, code] =
window.location.search.match(
/^(?=.*state=([^&]+)|)(?=.*code=([^&]+)|).+$/,
) || [];
fetchAccessToken(state, code);
}, []);
return (
<div>
<div>{accessToken}</div>
</div>
);
}