-
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
Merged
saseungmin
merged 2 commits into
CodeSoom:main
from
saseungmin:with-firebase-auth-login
Nov 29, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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로 감싸줘도 되지 않을까요?