refactor: social login buttons
This commit is contained in:
Vendored
+1
-1
@@ -26,5 +26,5 @@
|
|||||||
"[javascript]": {
|
"[javascript]": {
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
},
|
},
|
||||||
"cSpell.words": ["btns", "rustchat"]
|
"cSpell.words": ["btns", "oidc", "rustchat"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ const baseQueryWithTokenCheck = async (args, api, extraOptions) => {
|
|||||||
break;
|
break;
|
||||||
case 500:
|
case 500:
|
||||||
{
|
{
|
||||||
toast.error(result.error.data || "server error");
|
toast.error(result.error.data || "Server Error");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 401:
|
case 401:
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// import { useState, useEffect } from "react";
|
|
||||||
// import { useGoogleLogin } from "react-google-login";
|
|
||||||
import IconGithub from "../../assets/icons/github.svg";
|
import IconGithub from "../../assets/icons/github.svg";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import Button from "./styled/Button";
|
import Button from "./styled/Button";
|
||||||
@@ -20,8 +18,12 @@ const StyledSocialButton = styled(Button)`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default function GithubLoginButton({ config = {} }) {
|
type Props = {
|
||||||
const { client_id } = config;
|
client_id: string;
|
||||||
|
type?: "login" | "register";
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function GithubLoginButton({ type = "login", client_id }: Props) {
|
||||||
const handleGithubLogin = () => {
|
const handleGithubLogin = () => {
|
||||||
location.href = `http://github.com/login/oauth/authorize?client_id=${client_id}`;
|
location.href = `http://github.com/login/oauth/authorize?client_id=${client_id}`;
|
||||||
// console.log("github login");
|
// console.log("github login");
|
||||||
@@ -30,8 +32,7 @@ export default function GithubLoginButton({ config = {} }) {
|
|||||||
return (
|
return (
|
||||||
<StyledSocialButton onClick={handleGithubLogin}>
|
<StyledSocialButton onClick={handleGithubLogin}>
|
||||||
<IconGithub className="icon" />
|
<IconGithub className="icon" />
|
||||||
Sign in with Github
|
{` ${type === "login" ? "Sign in" : "Sign up"} with Github`}
|
||||||
{/* {loaded ? `Sign in with Github` : `Initailizing`} */}
|
|
||||||
</StyledSocialButton>
|
</StyledSocialButton>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,10 @@ const StyledSocialButton = styled(Button)`
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
clientId: string;
|
clientId: string;
|
||||||
|
type?: "login" | "register";
|
||||||
}
|
}
|
||||||
|
|
||||||
const GoogleLoginButton: FC<Props> = ({ clientId }) => {
|
const GoogleLoginButton: FC<Props> = ({ type = "login", clientId }) => {
|
||||||
const [login, { isSuccess, isLoading }] = useLoginMutation();
|
const [login, { isSuccess, isLoading }] = useLoginMutation();
|
||||||
|
|
||||||
const { signIn, loaded } = useGoogleLogin({
|
const { signIn, loaded } = useGoogleLogin({
|
||||||
@@ -60,7 +61,7 @@ const GoogleLoginButton: FC<Props> = ({ clientId }) => {
|
|||||||
return (
|
return (
|
||||||
<StyledSocialButton disabled={!loaded || isLoading} onClick={handleGoogleLogin}>
|
<StyledSocialButton disabled={!loaded || isLoading} onClick={handleGoogleLogin}>
|
||||||
<img className="icon" src={googleSvg} alt="google icon" />
|
<img className="icon" src={googleSvg} alt="google icon" />
|
||||||
{loaded ? `Sign in with Google` : `Initailizing`}
|
{loaded ? `${type === "login" ? "Sign in" : "Sign up"} with Google` : `Initializing`}
|
||||||
</StyledSocialButton>
|
</StyledSocialButton>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,13 +84,18 @@ export default function LoginPage() {
|
|||||||
toast.error(error.data);
|
toast.error(error.data);
|
||||||
break;
|
break;
|
||||||
case 401:
|
case 401:
|
||||||
toast.error("username or password incorrect");
|
toast.error("Username or Password incorrect");
|
||||||
break;
|
break;
|
||||||
case 404:
|
case 404:
|
||||||
toast.error("account not exsit");
|
toast.error("Account not exist");
|
||||||
|
break;
|
||||||
|
case 410:
|
||||||
|
toast.error(
|
||||||
|
"No associated account found, please contact admin for an invitation link to join."
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
toast.error("something error");
|
toast.error("Something Error");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -173,7 +178,7 @@ export default function LoginPage() {
|
|||||||
{hasDivider && <hr className="or" />}
|
{hasDivider && <hr className="or" />}
|
||||||
{enableMagicLink && <MagicLinkLogin />}
|
{enableMagicLink && <MagicLinkLogin />}
|
||||||
{googleLogin && <GoogleLoginButton clientId={clientId} />}
|
{googleLogin && <GoogleLoginButton clientId={clientId} />}
|
||||||
{enableGithubLogin && <GithubLoginButton config={githubAuthConfig} />}
|
{enableGithubLogin && <GithubLoginButton client_id={githubAuthConfig?.client_id} />}
|
||||||
{enableMetamaskLogin && <MetamaskLoginButton login={login} />}
|
{enableMetamaskLogin && <MetamaskLoginButton login={login} />}
|
||||||
{oidc.length > 0 && <OidcLoginButton issuers={oidc} />}
|
{oidc.length > 0 && <OidcLoginButton issuers={oidc} />}
|
||||||
{whoCanSignUp === "EveryOne" && <SignUpLink />}
|
{whoCanSignUp === "EveryOne" && <SignUpLink />}
|
||||||
|
|||||||
@@ -139,8 +139,10 @@ export default function Reg() {
|
|||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
<hr className="or" />
|
<hr className="or" />
|
||||||
{googleLogin && <GoogleLoginButton clientId={clientId} />}
|
{googleLogin && <GoogleLoginButton type="register" clientId={clientId} />}
|
||||||
{enableGithubLogin && <GithubLoginButton config={githubAuthConfig} />}
|
{enableGithubLogin && (
|
||||||
|
<GithubLoginButton type="register" client_id={githubAuthConfig?.client_id} />
|
||||||
|
)}
|
||||||
<SignInLink />
|
<SignInLink />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { Outlet } from "react-router-dom";
|
import { Outlet } from "react-router-dom";
|
||||||
// import { useMatch } from "react-router-dom";
|
|
||||||
|
|
||||||
import StyledWrapper from "./styled";
|
import StyledWrapper from "./styled";
|
||||||
|
|
||||||
export default function RegContainer() {
|
export default function RegContainer() {
|
||||||
|
|||||||
Reference in New Issue
Block a user