diff --git a/src/pages/login/GitHub.tsx b/src/pages/login/GitHub.tsx new file mode 100644 index 0000000..7ed2e95 --- /dev/null +++ b/src/pages/login/GitHub.tsx @@ -0,0 +1,75 @@ +import * as pages from "codeforlife/components/page" +import { type FC, useEffect } from "react" +import Button from "@mui/material/Button" +import CflLogoImage from "../../images/cfl_logo.png" +import GitHubMarkWhiteImage from "../../images/github-mark-white.png" +import { Image } from "codeforlife/components" +import { useLoginWithGitHubMutation } from "../../api/session" + +export interface GitHubProps {} + +const GitHub: FC = () => { + const [loginWithGitHub] = useLoginWithGitHubMutation() + + const handleLogin = () => { + window.location.href = `https://github.com/login/oauth/authorize?client_id=Ov23liBErSabQFqROeMg` + } + + useEffect(() => { + const urlParams = new URLSearchParams(window.location.search) + const code = urlParams.get("code") + + if (code) { + urlParams.delete("code") + window.history.replaceState(null, "", window.location.pathname) + loginWithGitHub({ code }) + .unwrap() + .then(() => { + window.location.href = "/agreement-signatures" + }) + .catch(err => { + alert(`Login failed: ${err}`) + }) + } + }, [loginWithGitHub]) + + return ( + + +
+ code for life logo + +
+
+
+ ) +} + +export default GitHub