// react import { useEffect, useState, FC } from "react"; // next import Link from "next/link"; import Image from "next/image"; import { useRouter } from "next/router"; import { useTheme } from "next-themes"; // images import githubLightModeImage from "/public/logos/github-black.png"; import githubDarkModeImage from "/public/logos/github-dark.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); // router const { query: { code }, } = useRouter(); // theme const { resolvedTheme } = 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 (
); };