fix: magic link login while invite only
This commit is contained in:
@@ -2,7 +2,8 @@ import { FC, useEffect } from "react";
|
||||
import { useGoogleLogin } from "react-google-login";
|
||||
import toast from "react-hot-toast";
|
||||
import styled from "styled-components";
|
||||
import googleSvg from "../../assets/icons/google.svg?url";
|
||||
import { KEY_LOCAL_MAGIC_TOKEN } from "../../app/config";
|
||||
import IconGoogle from "../../assets/icons/google.svg";
|
||||
import Button from "./styled/Button";
|
||||
import { useLoginMutation } from "../../app/services/auth";
|
||||
|
||||
@@ -29,7 +30,8 @@ interface Props {
|
||||
|
||||
const GoogleLoginButton: FC<Props> = ({ type = "login", clientId }) => {
|
||||
const [login, { isSuccess, isLoading }] = useLoginMutation();
|
||||
|
||||
//拿本地存的magic token
|
||||
const magic_token = localStorage.getItem(KEY_LOCAL_MAGIC_TOKEN);
|
||||
const { signIn, loaded } = useGoogleLogin({
|
||||
onScriptLoadFailure: (wtf) => {
|
||||
console.error("google login script load failure", wtf);
|
||||
@@ -38,6 +40,7 @@ const GoogleLoginButton: FC<Props> = ({ type = "login", clientId }) => {
|
||||
onSuccess: ({ tokenId, ...rest }) => {
|
||||
console.info("google oauth success", tokenId, rest);
|
||||
login({
|
||||
magic_token,
|
||||
id_token: tokenId,
|
||||
type: "google"
|
||||
});
|
||||
@@ -60,7 +63,7 @@ const GoogleLoginButton: FC<Props> = ({ type = "login", clientId }) => {
|
||||
// console.log("google login ", loaded);
|
||||
return (
|
||||
<StyledSocialButton disabled={!loaded || isLoading} onClick={handleGoogleLogin}>
|
||||
<img className="icon" src={googleSvg} alt="google icon" />
|
||||
<IconGoogle className="icon" alt="google icon" />
|
||||
{loaded ? `${type === "login" ? "Sign in" : "Sign up"} with Google` : `Initializing`}
|
||||
</StyledSocialButton>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user