import { Button } from '@mui/material';
import { getSession, signOut, useSession } from 'next-auth/react';
import ProfileContent from '../../components/profile-content/ProfileContent';
import { LOGIN_PAGE } from '../../constants/pages';

const ProfilePage = () => {
  const { data: session } = useSession();

  console.log(session);

  function logoutHandler() {
    signOut();
  }
  return (
    <>
      <ProfileContent></ProfileContent>
      <Button color="inherit" onClick={logoutHandler}>
        Logout
      </Button>
    </>
  );
};

export async function getServerSideProps(context) {
  const session = await getSession({ req: context.req });

  if (!session) {
    return {
      redirect: {
        destination: LOGIN_PAGE,
        permanent: false,
      },
    };
  }

  return {
    props: { session },
  };
}

export default ProfilePage;
