import { useSession } from "@xtablo/shared/contexts/SessionContext";
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";

export const OAuthSigninPage = () => {
  const navigate = useNavigate();
  const { session } = useSession();
  const redirectUrl = localStorage.getItem("redirectUrl");
  useEffect(() => {
    const interval = setInterval(() => {
      if (session) {
        if (redirectUrl) {
          localStorage.removeItem("redirectUrl");
          navigate(decodeURIComponent(redirectUrl));
        } else {
          navigate("/");
        }
      }
    }, 100);
    return () => clearInterval(interval);
  }, [navigate, session]);
  return <></>;
};
