import React, { FC, PropsWithChildren, useState } from 'react'
import { observer } from 'mobx-react-lite'
import { AuthStore } from '../stores/AuthStore'
import { Navigate, useLocation } from 'react-router-dom'
import { Paths } from './Paths'

export const RequireAuth: FC<PropsWithChildren> = observer(({ children }) => {
	const [store] = useState(AuthStore.instance())
	const location = useLocation()
	if (!store.logined) {
		return <Navigate to={Paths.Login} state={{ from: location }} replace />
	}
	return <>{children}</>
})
