import { useEffect, useState, FC } from "react"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/router"; // next-themes import { useTheme } from "next-themes"; // images import githubBlackImage from "public/logos/github-black.svg"; import githubWhiteImage from "public/logos/github-white.svg"; type Props = { handleSignIn: React.Dispatch; clientId: string; }; export const GitHubSignInButton: FC = (props) => { const { handleSignIn, clientId } = props; // states const [loginCallBackURL, setLoginCallBackURL] = useState(undefined); const [gitCode, setGitCode] = useState(null); const router = useRouter(); const { code } = router.query; const { theme } = useTheme(); useEffect(() => { if (code && !gitCode) { setGitCode(code.toString()); handleSignIn(code.toString()); } }, [code, gitCode, handleSignIn]); useEffect(() => { const origin = typeof window !== "undefined" && window.location.origin ? window.location.origin : ""; setLoginCallBackURL(`${origin}/` as any); }, []); return (
); };