refactor: github oauth

This commit is contained in:
Tristan Yang
2022-11-14 18:57:23 +08:00
parent 821c1d1112
commit 126cbc39a2
4 changed files with 91 additions and 3 deletions
+44
View File
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.tip {
color: #555;
}
.error {
visibility: hidden;
color: red;
}
body.error .tip {
visibility: hidden;
}
body.error .error {
visibility: visible;
}
</style>
</head>
<body>
<h1 class="tip">WebApp GitHub OAuth Callback Page</h1>
<h1 class="error">Code not found</h1>
<script>
const code = new URLSearchParams(location.search).get("code");
if (code) {
location.href = `${location.origin}/?code=${code}#/cb/github/webapp`;
} else {
document.body.classList.add("error");
}
</script>
</body>
</html>
+44
View File
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.tip {
color: #555;
}
.error {
visibility: hidden;
color: red;
}
body.error .tip {
visibility: hidden;
}
body.error .error {
visibility: visible;
}
</style>
</head>
<body>
<h1 class="tip">Widget GitHub OAuth Callback Page</h1>
<h1 class="error">Code not found</h1>
<script>
const code = new URLSearchParams(location.search).get("code");
if (code) {
location.href = `${location.origin}/?code=${code}#/cb/github/widget`;
} else {
document.body.classList.add("error");
}
</script>
</body>
</html>
+1 -1
View File
@@ -49,7 +49,7 @@ const GithubLoginButton: FC<Props> = ({ type = "login", source = "webapp", clien
}, [source]); }, [source]);
const handleGithubLogin = () => { const handleGithubLogin = () => {
window.open(`https://github.com/login/oauth/authorize?client_id=${client_id}&redirect_uri=${location.origin}/#/cb/github/${source}`); window.open(`https://github.com/login/oauth/authorize?client_id=${client_id}&redirect_uri=${location.origin}/github/cb/${source}.html`);
// location.href = `https://github.com/login/oauth/authorize?client_id=${client_id}`; // location.href = `https://github.com/login/oauth/authorize?client_id=${client_id}`;
}; };
+2 -2
View File
@@ -7,7 +7,7 @@ type Props = {
needLogin?: boolean needLogin?: boolean
} }
const Index = ({ needLogin = false }: Props) => { const Index = ({ needLogin = false }: Props) => {
const { name, logo } = useAppSelector(store => store.server); const { logo } = useAppSelector(store => store.server);
return ( return (
<> <>
<div className="group relative flex justify-start items-start mb-3"> <div className="group relative flex justify-start items-start mb-3">
@@ -22,7 +22,7 @@ const Index = ({ needLogin = false }: Props) => {
</div> </div>
</div> </div>
</div> </div>
{needLogin && <div className="pl-14 animate-[fadeInUp_.5s_1.2s_ease-in-out_both]"> {needLogin && <div className="pl-14 animate-[fadeInUp_.5s_ease-in-out_both]">
<Login /> <Login />
</div>} </div>}
</> </>