App.tsx
1.05 KB
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
import React from "react";
import { Switch, Route, Redirect } from "react-router-dom";
import { Login } from "auth/Login";
import { Signup } from "auth/Signup";
import { useAuth, TokenContext } from "auth/useAuth";
import { Page } from "layout/Page";
import { FileList } from "file/FileList";
export function App() {
const token = useAuth();
const root = token?.token?.user.rootFolder;
return (
<Switch>
<Route path="/login">
<Login login={token.login} />
</Route>
<Route path="/signup">
<Signup />
</Route>
<Route>
{token.token !== null ? (
<TokenContext.Provider value={token}>
<Page>
<Switch>
<Route path="/folder/:id">
<FileList />
</Route>
<Route>
<Redirect to={`/folder/${root}`} />
</Route>
</Switch>
</Page>
</TokenContext.Provider>
) : (
<Redirect to="/login" />
)}
</Route>
</Switch>
);
}