import { useHandleSignInCallback } from '@logto/react';
import { Spin } from 'antd';
import { useEffect } from 'react';
import { useNavigate } from 'react-router';

export const CallbackPage = () => {
  const navigate = useNavigate();
  const { isLoading, isAuthenticated } = useHandleSignInCallback();
  useEffect(() => {
    if (!isAuthenticated) return;
    const redirect = sessionStorage.getItem('redirect');
    if (redirect) {
      sessionStorage.removeItem('redirect');
      navigate(redirect);
    } else {
      navigate('/user-center');
    }
  }, [isAuthenticated]);
  if (isLoading) {
    return (
      <Spin spinning>
        <div style={{ height: '100vh', width: '100vw' }} />
      </Spin>
    );
  }
  return null;
};