import type { NextPage } from 'next';
import React, { useState, useEffect } from 'react';
import {
  BrowserRouter,
  Routes,
  Route,
} from "react-router-dom";
import { useRouter } from 'next/router'
import { useSelector } from 'react-redux';
import { Main } from './main'
import { Login } from './login';

import { selectTokenData } from '../../redux/login/selectors';

const Index: NextPage = () => {
  const router = useRouter();
  const { token, status_token } = useSelector(selectTokenData);
  const [login, setLogin] = useState(false);

  useEffect(() => {
   // token.length ? router.push('/admin/main'): router.push('/admin/login')
    console.log(status_token, 'token');
   //setLogin(true);

  });

  return (
   <></>
  )
}

export async function getServerSideProps({ req, res }) {
  const { token, status_token } = useSelector(selectTokenData);
  // await dbConnect();
  // const user = await getUser(req, res);
   if (!token) {
     return {
       redirect: {
         permanent: false,
         destination: "/signin",
       },
       props: {},
     };
   }
   return {
     props: {
       user,
     },
   };
 }
 

export default Index;
