From 7e75d3ac915e93341ac8a8f3e93b87f9f09cd279 Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Thu, 29 Aug 2024 15:41:51 +0000 Subject: [PATCH] add gh login --- src/pages/login/GitHub.tsx | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/pages/login/GitHub.tsx 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