-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathapp.tsx
65 lines (61 loc) · 1.69 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
55
56
57
58
59
60
61
62
63
64
65
import { useContext } from 'react';
import {
Navigate,
Route,
HashRouter as Router,
Routes,
useLocation,
} from 'react-router-dom';
import { Loading } from './components/Loading';
import { Sidebar } from './components/Sidebar';
import { AppContext, AppProvider } from './context/App';
import { LoginRoute } from './routes/Login';
import { LoginEnterpriseRoute } from './routes/LoginEnterprise';
import { LoginWithToken } from './routes/LoginWithToken';
import { NotificationsRoute } from './routes/Notifications';
import { SettingsRoute } from './routes/Settings';
function RequireAuth({ children }) {
const { isLoggedIn } = useContext(AppContext);
const location = useLocation();
return isLoggedIn ? (
children
) : (
<Navigate to="/login" replace state={{ from: location }} />
);
}
export const App = () => {
return (
<AppProvider>
<Router>
<div className="flex flex-col pl-14 h-full">
<Loading />
<Sidebar />
<Routes>
<Route
path="/"
element={
<RequireAuth>
<NotificationsRoute />
</RequireAuth>
}
/>
<Route
path="/settings"
element={
<RequireAuth>
<SettingsRoute />
</RequireAuth>
}
/>
<Route path="/login" element={<LoginRoute />} />
<Route
path="/login-enterprise"
element={<LoginEnterpriseRoute />}
/>
<Route path="/login-token" element={<LoginWithToken />} />
</Routes>
</div>
</Router>
</AppProvider>
);
};