Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
[Feature] With firebase auth login and used localStorage#41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,41 @@ | ||
| import React from 'react'; | ||
| import { useDispatch } from 'react-redux'; | ||
| import { Switch, Route } from 'react-router-dom'; | ||
| import { loadItem } from './services/storage'; | ||
| import { setUser } from './reducers/slice'; | ||
| import MainPage from './pages/MainPage'; | ||
| import WritePage from './pages/WritePage'; | ||
| import IntroducePage from './pages/IntroducePage'; | ||
| import LoginPage from './pages/LoginPage'; | ||
| import RegisterPage from './pages/RegisterPage'; | ||
| import HeaderContainer from './containers/common/HeaderContainer'; | ||
| const App = () => ( | ||
| <> | ||
| <HeaderContainer /> | ||
| <Switch> | ||
| <Route exact path="/" component={MainPage} /> | ||
| <Route path="/introduce/:id" component={IntroducePage} /> | ||
| <Route component={LoginPage} path="/login" /> | ||
| <Route component={RegisterPage} path="/register" /> | ||
| <Route path="/write" component={WritePage} /> | ||
| </Switch> | ||
| </> | ||
| ); | ||
| const App = () => { | ||
| const dispatch = useDispatch(); | ||
| const user = loadItem('user'); | ||
| if (user) { | ||
| const { email } = user; | ||
| dispatch(setUser(email)); | ||
| } | ||
| return ( | ||
| <> | ||
| <HeaderContainer /> | ||
| <Switch> | ||
| <Route exact path="/" component={MainPage} /> | ||
| <Route path="/introduce/:id" component={IntroducePage} /> | ||
| <Route component={LoginPage} path="/login" /> | ||
| <Route component={RegisterPage} path="/register" /> | ||
| <Route path="/write" component={WritePage} /> | ||
| </Switch> | ||
| </> | ||
| ); | ||
| }; | ||
| export default App; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -14,6 +14,7 @@ const RegisterFormContainer = () => { | ||
| const register = useSelector(get('register')); | ||
| const auth = useSelector(get('auth')); | ||
| const user = useSelector(get('user')); | ||
| const authError = useSelector(get('authError')); | ||
| const onChangeRegisterField = useCallback(({ name, value }) => { | ||
| @@ -27,23 +28,31 @@ const RegisterFormContainer = () => { | ||
| }, [dispatch]); | ||
| const onSubmit = useCallback(() => { | ||
| // TODO: 회원가입 validation 체크 로직 추가 | ||
| dispatch(requestRegister()); | ||
| }, [dispatch]); | ||
| useEffect(() => { | ||
| if (user) { | ||
| history.push('/'); | ||
| } | ||
| }, [user]); | ||
| useEffect(() => { | ||
| if (auth) { | ||
| history.push('/login'); | ||
| } | ||
| if (authError) { | ||
| // TODO: 추 후 error 처리 | ||
| // TODO: error 처리 추가 | ||
| console.error(authError); | ||
| } | ||
| }, [auth, authError]); | ||
| return () => { | ||
| dispatch(clearAuth()); | ||
| }; | ||
| }, [dispatch, auth, authError]); | ||
| useEffect(() => () => { | ||
| dispatch(clearAuth()); | ||
| }, [dispatch]); | ||
Comment on lines
+53
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분이 호출되는 시점이 어떻게 될까요? | ||
| return ( | ||
| <AuthForm | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,19 @@ | ||
| import React from 'react'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { get } from '../../util/utils'; | ||
| import Header from '../../components/common/Header'; | ||
| const HeaderContainer = () => (( | ||
| <Header /> | ||
| ) | ||
| ); | ||
| const HeaderContainer = () => { | ||
| const user = useSelector(get('user')); | ||
| return ( | ||
| <Header | ||
| user={user} | ||
| /> | ||
| ); | ||
| }; | ||
| export default HeaderContainer; |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useEffect로 감싸줘도 되지 않을까요?