-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
54 lines (48 loc) · 1.24 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { useEffect, useState } from 'react'
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
import { Toaster } from 'react-hot-toast'
import Modal from 'react-modal'
import { venlyConnect } from './libs/venlyConnect'
import Alerts from './components/Alerts'
import Nav from './components/Nav'
import Loading from './pages/Loading'
Modal.setAppElement('#root')
export default function App() {
const navigate = useNavigate();
const location = useLocation();
const [isLoading, setIsLoading] = useState(true)
useEffect(() => {
checkAuthenticated()
}, [])
async function checkAuthenticated() {
try {
const res = await venlyConnect.checkAuthenticated()
if (!res?.isAuthenticated)
navigate('/login', { replace: true })
}
catch(error) {
console.log('error')
navigate('/login', { replace: true })
}
setIsLoading(false)
}
if (isLoading) {
return <Loading />
}
else if (location.pathname == '/login')
return <Outlet />
return <>
<Nav />
<div className="main">
<Outlet />
</div>
<Alerts />
<Toaster
position="bottom-center"
containerClassName="toast-container"
toastOptions={{
className: "toast"
}}
/>
</>
}