forked from github/plane
44f8ba407d
* auth integration fixes * auth integration fixes * auth integration fixes * auth integration fixes * dev: update user api to return fallback workspace and improve the structure of the response * dev: fix the issue keyerror and move onboarding logic to serializer method field * dev: use-user-auth hook imlemented for route access validation and build issues resolved effected by user payload * fix: global theme color fix * style: new onboarding ui , fix: use-user-auth hook implemented * fix: command palette, project invite modal and issue detail page mutation type fix * fix: onboarding redirection fix * dev: build isuue resolved * fix: use user auth hook fix * fix: sign in toast alert fix, sign out redirection fix and user theme error fix * fix: user response fix * fix: unAuthorizedStatus logic updated --------- Co-authored-by: pablohashescobar <nikhilschacko@gmail.com> Co-authored-by: gurusainath <gurusainath007@gmail.com> Co-authored-by: anmolsinghbhatia <anmolsinghbhatia@caravel.tech>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { useEffect, useState, FC } from "react";
|
|
import Link from "next/link";
|
|
import Image from "next/image";
|
|
import { useRouter } from "next/router";
|
|
// images
|
|
import githubImage from "/public/logos/github-black.png";
|
|
|
|
const { NEXT_PUBLIC_GITHUB_ID } = process.env;
|
|
|
|
export interface GithubLoginButtonProps {
|
|
handleSignIn: React.Dispatch<string>;
|
|
}
|
|
|
|
export const GithubLoginButton: FC<GithubLoginButtonProps> = (props) => {
|
|
const { handleSignIn } = props;
|
|
// router
|
|
const {
|
|
query: { code },
|
|
} = useRouter();
|
|
// states
|
|
const [loginCallBackURL, setLoginCallBackURL] = useState(undefined);
|
|
|
|
useEffect(() => {
|
|
if (code) {
|
|
handleSignIn(code.toString());
|
|
}
|
|
}, [code, handleSignIn]);
|
|
|
|
useEffect(() => {
|
|
const origin =
|
|
typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
|
|
setLoginCallBackURL(`${origin}/` as any);
|
|
}, []);
|
|
|
|
return (
|
|
<div className="w-full px-1">
|
|
<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-3 rounded-md border border-brand-base p-2 text-sm font-medium text-brand-secondary duration-300 hover:bg-brand-surface-2">
|
|
<Image src={githubImage} height={22} width={22} color="#000" alt="GitHub Logo" />
|
|
<span>Sign In with Github</span>
|
|
</button>
|
|
</Link>
|
|
</div>
|
|
);
|
|
};
|