I'm getting TypeError: cannot destructure property 'name' of 'response.profileObj' as it is undefined

33 views Asked by At

instead of redirecting me to the home page , it is giving me error I even tried using if-else for error but still it gave me 'reponse.profileObj' is undefined

What should I do to avoid this and after using null check, it aint redirecting me to the home page

const Login = () => {
  const navigate = useNavigate();
  const responseGoogle = (response) => {
    localStorage.setItem("user", JSON.stringify(response.profileObj));
    if (response.profileObj) {
      const { name, googleId, imageUrl } = response.profileObj;

      const doc = {
        _id:googleId,
        _type: "user",
        userName:name,
        image:imageUrl,
      };

      client.createIfNotExists(doc).then(() => {
        navigate("/", { replace: true });
      });
    }
  };
  return (
    <div className="flex justify-start items-center flex-col h-screen">
      <div className="relative w-full h-full">
        <video
          src={video}
          type="video/mp4"
          autoPlay
          loop
          muted
          controls={false}
          className="w-full h-full object-cover"
        />
        <div className="absolute flex flex-col justify-center items-center top-0 right-0 left-0 bottom-0 bg-blackOverlay">
          <div className="p-5">
            <img src={logoo} width="250px" alt="logo" />
          </div>

          <div className="shadow-2xl">
            <GoogleLogin
              clientId={process.env.REACT_APP_GOOGLE_API_TOKEN}
              render={(renderProps) => (
                <button
                  type="button"
                  className="bg-mainColor flex justify-center items-center p-2 rounded-lg outline-none cursor-pointer"
                  onClick={renderProps.onClick}
                  disabled={renderProps.disabled}
                >
                  <FcGoogle className="mr-6 " /> Sign In with Google
                </button>
              )}
              onSuccess={responseGoogle}
              onFailure={responseGoogle}
              cookiePolicy="single_host_origin"
            />
          </div>
        </div>
      </div>
    </div>
  );
};
0

There are 0 answers