|
1 | | -import { useState, useEffect } from 'react'; |
2 | | -import { Routes, Route, useNavigate, useLocation } from 'react-router-dom'; |
| 1 | +import { useEffect, useState } from 'react'; |
| 2 | +import { Route, Routes, useLocation, useNavigate } from 'react-router-dom'; |
3 | 3 | import { getAuth } from 'src/apis/auth'; |
4 | 4 | import UserContext from 'src/contexts/user'; |
5 | 5 | import { LoadingPage, LoginPage, OAuthPage, WorkspacePage } from 'src/pages'; |
6 | | -import { User } from 'src/types/user'; |
| 6 | +import { UserInfo } from 'src/types/user'; |
| 7 | + |
7 | 8 | import 'styles/reset.scss'; |
8 | 9 |
|
9 | 10 | function App() { |
10 | 11 | const [isLoaded, setIsLoaded] = useState<boolean>(false); |
11 | | - const [user, setUser] = useState<User | null>(null); |
| 12 | + const [userInfo, setUserInfo] = useState<UserInfo | null>(null); |
12 | 13 |
|
13 | 14 | const navigate = useNavigate(); |
14 | 15 | const location = useLocation(); |
15 | 16 |
|
16 | 17 | const autoLogin = async () => { |
17 | | - const currentUser = await getAuth(); |
| 18 | + const { user, workspaces } = await getAuth(); |
18 | 19 |
|
19 | 20 | setIsLoaded(true); |
20 | 21 |
|
21 | | - if (!currentUser) { |
22 | | - if (location.pathname === '/workspace') navigate('/'); |
| 22 | + if (!user) { |
| 23 | + if (location.pathname.match('/workspace')) navigate('/'); |
23 | 24 | return; |
24 | 25 | } |
25 | 26 |
|
26 | | - setUser(currentUser); |
27 | | - navigate('/workspace'); |
| 27 | + setUserInfo({ user, workspaces }); |
| 28 | + |
| 29 | + const { id } = workspaces[0]; |
| 30 | + navigate(`/workspace/${id}`); |
28 | 31 | }; |
29 | 32 |
|
30 | 33 | useEffect(() => { |
31 | 34 | autoLogin(); |
32 | 35 | }, []); |
33 | 36 |
|
34 | 37 | return isLoaded ? ( |
35 | | - <UserContext.Provider value={{ user, setUser }}> |
| 38 | + <UserContext.Provider value={{ userInfo, setUserInfo }}> |
36 | 39 | <Routes> |
37 | 40 | <Route path="/" element={<LoginPage />} /> |
38 | 41 | <Route path="/oauth" element={<OAuthPage />} /> |
39 | | - <Route path="/workspace" element={<WorkspacePage />} /> |
| 42 | + <Route path="/workspace/:id" element={<WorkspacePage />} /> |
40 | 43 | </Routes> |
41 | 44 | </UserContext.Provider> |
42 | 45 | ) : ( |
|
0 commit comments