import { useEffect, useState, FC } from "react"; import Link from "next/link"; import Image from "next/image"; import { useRouter } from "next/navigation"; // next-themes import { useTheme } from "next-themes"; // images import githubBlackImage from "public/logos/github-black.svg"; import githubWhiteImage from "public/logos/github-white.svg"; export interface GithubLoginButtonProps { handleSignIn: React.Dispatch; clientId: string; } export const GithubLoginButton: 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 (
); };