forked from github/plane
1e152c666c
* chore: moved app & space from apps to root * chore: modified workspace configuration * chore: modified dockerfiles for space and web * chore: modified icons for space * feat: updated files for new svg icons supported by next-images * chore: added /spaces base path for next * chore: added compose config for space * chore: updated husky configuration * chore: updated workflows for new configuration * chore: changed app name to web * fix: resolved build errors with web * chore: reset file tracing root for both projects * chore: added nginx config for deploy * fix: eslint and tsconfig settings for space app * husky setup fixes based on new dir * eslint fixes * prettier formatting --------- Co-authored-by: Henit Chobisa <chobisa.henit@gmail.com>
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { useEffect, useState, FC } from "react";
|
|
|
|
import Link from "next/link";
|
|
import Image from "next/image";
|
|
import { useRouter } from "next/router";
|
|
|
|
// next-themes
|
|
import { useTheme } from "next-themes";
|
|
// images
|
|
import githubBlackImage from "/public/logos/github-black.png";
|
|
import githubWhiteImage from "/public/logos/github-white.png";
|
|
|
|
const { NEXT_PUBLIC_GITHUB_ID } = process.env;
|
|
|
|
export interface GithubLoginButtonProps {
|
|
handleSignIn: React.Dispatch<string>;
|
|
}
|
|
|
|
export const GithubLoginButton: FC<GithubLoginButtonProps> = ({ handleSignIn }) => {
|
|
const [loginCallBackURL, setLoginCallBackURL] = useState(undefined);
|
|
const [gitCode, setGitCode] = useState<null | string>(null);
|
|
|
|
const {
|
|
query: { code },
|
|
} = useRouter();
|
|
|
|
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 (
|
|
<div className="w-full flex justify-center items-center">
|
|
<Link
|
|
href={`https://github.com/login/oauth/authorize?client_id=${NEXT_PUBLIC_GITHUB_ID}&redirect_uri=${loginCallBackURL}&scope=read:user,user:email`}
|
|
>
|
|
<button className="flex w-full items-center justify-center gap-2 rounded border border-custom-border-300 p-2 text-sm font-medium text-custom-text-100 duration-300 hover:bg-custom-background-80 h-[46px]">
|
|
<Image
|
|
src={theme === "dark" ? githubWhiteImage : githubBlackImage}
|
|
height={20}
|
|
width={20}
|
|
alt="GitHub Logo"
|
|
/>
|
|
<span>Sign in with GitHub</span>
|
|
</button>
|
|
</Link>
|
|
</div>
|
|
);
|
|
};
|