chore: update auth buttons
This commit is contained in:
@@ -7,12 +7,15 @@ import { StyledSocialButton } from "./styled";
|
|||||||
import Onboarding from "@metamask/onboarding";
|
import Onboarding from "@metamask/onboarding";
|
||||||
import { LoginCredential } from "../../types/auth";
|
import { LoginCredential } from "../../types/auth";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { AuthType } from "../../types/common";
|
||||||
// import toast from "react-hot-toast";
|
// import toast from "react-hot-toast";
|
||||||
|
|
||||||
export default function MetamaskLoginButton({
|
export default function MetamaskLoginButton({
|
||||||
login
|
login,
|
||||||
|
type = "login"
|
||||||
}: {
|
}: {
|
||||||
login: (params: LoginCredential) => void;
|
login: (params: LoginCredential) => void;
|
||||||
|
type?: AuthType
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation("auth");
|
const { t } = useTranslation("auth");
|
||||||
const [requesting, setRequesting] = useState(false);
|
const [requesting, setRequesting] = useState(false);
|
||||||
@@ -93,7 +96,7 @@ export default function MetamaskLoginButton({
|
|||||||
return (
|
return (
|
||||||
<StyledSocialButton disabled={requesting} onClick={handleMetamaskLogin}>
|
<StyledSocialButton disabled={requesting} onClick={handleMetamaskLogin}>
|
||||||
<img className="icon" src={metamaskSvg} alt="meta mask icon" />
|
<img className="icon" src={metamaskSvg} alt="meta mask icon" />
|
||||||
{t("login.metamask")}
|
{type == "login" ? t("login.metamask") : t("reg.metamask")}
|
||||||
</StyledSocialButton>
|
</StyledSocialButton>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import StyledButton from "../../common/component/styled/Button";
|
|||||||
import OidcLoginEntry from "./OidcLoginEntry";
|
import OidcLoginEntry from "./OidcLoginEntry";
|
||||||
import { OIDCConfig } from "../../types/auth";
|
import { OIDCConfig } from "../../types/auth";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { AuthType } from "../../types/common";
|
||||||
|
|
||||||
const StyledOidcLoginModal = styled(StyledModal)`
|
const StyledOidcLoginModal = styled(StyledModal)`
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -30,8 +31,9 @@ const StyledOidcLoginModal = styled(StyledModal)`
|
|||||||
`;
|
`;
|
||||||
interface IProps {
|
interface IProps {
|
||||||
issuers?: OIDCConfig[];
|
issuers?: OIDCConfig[];
|
||||||
|
type?: AuthType
|
||||||
}
|
}
|
||||||
const OidcLoginButton: FC<IProps> = ({ issuers }) => {
|
const OidcLoginButton: FC<IProps> = ({ issuers, type = "login" }) => {
|
||||||
const { t } = useTranslation("auth");
|
const { t } = useTranslation("auth");
|
||||||
const [modal, setModal] = useState(false);
|
const [modal, setModal] = useState(false);
|
||||||
if (!issuers) return null;
|
if (!issuers) return null;
|
||||||
@@ -42,7 +44,7 @@ const OidcLoginButton: FC<IProps> = ({ issuers }) => {
|
|||||||
setModal(true);
|
setModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("login.oidc")}
|
{type == "login" ? t("login.oidc") : t("reg.oidc")}
|
||||||
</StyledSocialButton>
|
</StyledSocialButton>
|
||||||
{modal && (
|
{modal && (
|
||||||
<Modal id="modal-modal">
|
<Modal id="modal-modal">
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ import MetamaskLoginButton from "./MetamaskLoginButton";
|
|||||||
import OidcLoginButton from "./OidcLoginButton";
|
import OidcLoginButton from "./OidcLoginButton";
|
||||||
import { useLoginMutation } from '../../app/services/auth';
|
import { useLoginMutation } from '../../app/services/auth';
|
||||||
import { LoginConfig } from '../../types/server';
|
import { LoginConfig } from '../../types/server';
|
||||||
|
import { AuthType } from '../../types/common';
|
||||||
|
|
||||||
// type Props = {}
|
type Props = {
|
||||||
|
type?: AuthType
|
||||||
|
}
|
||||||
|
|
||||||
const SocialLoginButtons = () => {
|
const SocialLoginButtons = ({ type = "login" }: Props) => {
|
||||||
const [login, { isSuccess }] = useLoginMutation();
|
const [login, { isSuccess }] = useLoginMutation();
|
||||||
const { config: githubAuthConfig } = useGithubAuthConfig();
|
const { config: githubAuthConfig } = useGithubAuthConfig();
|
||||||
const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery();
|
const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery();
|
||||||
@@ -34,12 +37,12 @@ const SocialLoginButtons = () => {
|
|||||||
const googleLogin = enableGoogleLogin && !!clientId;
|
const googleLogin = enableGoogleLogin && !!clientId;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{googleLogin && <GoogleLoginButton type="register" clientId={clientId} />}
|
{googleLogin && <GoogleLoginButton type={type} clientId={clientId} />}
|
||||||
{enableGithubLogin && (
|
{enableGithubLogin && (
|
||||||
<GithubLoginButton type="register" client_id={githubAuthConfig?.client_id} />
|
<GithubLoginButton type={type} client_id={githubAuthConfig?.client_id} />
|
||||||
)}
|
)}
|
||||||
{enableMetamaskLogin && <MetamaskLoginButton login={login} />}
|
{enableMetamaskLogin && <MetamaskLoginButton type={type} login={login} />}
|
||||||
{oidc.length > 0 && <OidcLoginButton issuers={oidc} />}
|
{oidc.length > 0 && <OidcLoginButton type={type} issuers={oidc} />}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ export default function Reg() {
|
|||||||
</form>
|
</form>
|
||||||
<hr className="or" />
|
<hr className="or" />
|
||||||
<div className="flex flex-col gap-3 py-3">
|
<div className="flex flex-col gap-3 py-3">
|
||||||
<SocialLoginButtons />
|
<SocialLoginButtons type="register" />
|
||||||
</div>
|
</div>
|
||||||
<SignInLink token={magicToken} />
|
<SignInLink token={magicToken} />
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user