-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: 로그인 api 연결 #185
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
Merged
Feat: 로그인 api 연결 #185
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6c0d222
feat: 헤더에 로그인 버튼 추가
efb522d
feat: 프로필 띄우기
9b1a00d
feat: redirect_local로 변경
kwonsaebom e1de1d9
style: 헤더 프로필에 pointer 추가
kwonsaebom 8db3c68
style: UserModal 이미지 모서리 스타일 변경
kwonsaebom 21beb01
feat: 토큰이 없으면 user 정보 불러오는 함수 작동하지 않도록 제한
kwonsaebom 4bd8884
feat: 로그인 함수 연결
kwonsaebom c9dcd97
feat: 빌드 에러 해결
kwonsaebom b0965f9
refactor: redirect_uri constant 사용
kwonsaebom f01fab8
fix: 로그인 모달 클릭시 자동 로그인 상태 제거
kwonsaebom 41c4147
feat: 로그인 상태 관리 대신 user 데이터 사용으로 변경
kwonsaebom db52e1b
fix: refetch 삭제
kwonsaebom a220342
fix: useEffect 제거
kwonsaebom 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,5 +1,5 @@ | ||
| export const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID; | ||
| export const GOOGLE_REDIRECT_URI = import.meta.env.VITE_GOOGLE_REDIRECT_URI; | ||
| export const GOOGLE_REDIRECT_URI = import.meta.env.VITE_GOOGLE_REDIRECT_URI_LOCAL; | ||
| export const GOOGLE_AUTH_BASE_URL = 'https://accounts.google.com/o/oauth2/v2/auth'; | ||
| export const GOOGLE_SCOPE = 'openid email profile'; | ||
| export const GOOGLE_RESPONSE_TYPE = 'code'; |
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
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,14 @@ | ||
| import { useState } from 'react'; | ||
| import { useEffect, useState } from 'react'; | ||
| import { useNavigate, useLocation, Link } from 'react-router-dom'; | ||
|
|
||
| import * as styles from './Header.css'; | ||
|
|
||
| import { PATH } from '@/route/path'; | ||
| import IcLogo from '@/assets/svg/IcLogo'; | ||
| import LoginModal from '@/common/component/LoginModal/LoginModal'; | ||
| import { useModal } from '@/common/hook/useModal'; | ||
| import { useGetUser } from '@/api/domain/signup/hook/useGetUser'; | ||
| import UserModal from '@/common/component/UserModal/UserModal'; | ||
|
|
||
| const MENUS = [ | ||
| { label: '나의 할 일', path: PATH.TODO }, | ||
|
|
@@ -16,16 +20,37 @@ const Header = () => { | |
| const navigate = useNavigate(); | ||
| const location = useLocation(); | ||
|
|
||
| const accessToken = localStorage.getItem('accessToken'); | ||
|
|
||
| const findActiveMenu = MENUS.find((menu) => location.pathname.startsWith(menu.path)); | ||
| const initialMenu = findActiveMenu ? findActiveMenu.label : ''; | ||
|
|
||
| const [activeMenu, setActiveMenu] = useState<string>(initialMenu); | ||
| const [isLoggedIn, setIsLoggedIn] = useState<boolean>(!!accessToken); | ||
| const [openProfile, setOpenProfile] = useState<boolean>(false); | ||
|
|
||
| const { openModal, closeModal, ModalWrapper } = useModal(); | ||
|
|
||
| const { data: user, isLoading } = useGetUser(); | ||
|
|
||
| useEffect(() => { | ||
| setIsLoggedIn(!!localStorage.getItem('accessToken')); | ||
| }, []); | ||
|
|
||
| const handleLogin = () => { | ||
| setIsLoggedIn(true); | ||
| openModal(<LoginModal onClose={closeModal} />); | ||
| }; | ||
|
Comment on lines
+40
to
+35
Collaborator
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. p1) 여기서 |
||
|
|
||
| const handleMenuClick = (menuLabel: string, path: string) => { | ||
| setActiveMenu(menuLabel); | ||
| navigate(path); | ||
| }; | ||
|
|
||
| const handleProfile = () => { | ||
| setOpenProfile((prev) => !prev); | ||
| }; | ||
|
|
||
| const renderNavMenu = () => ( | ||
| <> | ||
| <nav className={styles.navWrapper}> | ||
|
|
@@ -45,6 +70,17 @@ const Header = () => { | |
| ); | ||
| })} | ||
| </nav> | ||
| {!isLoading && user && ( | ||
| <> | ||
| <img | ||
| src={user.profileImageUrl} | ||
| alt="유저 프로필" | ||
| className={styles.profilePlaceholder} | ||
| onClick={handleProfile} | ||
| /> | ||
| {openProfile && <UserModal onClose={handleProfile} />} | ||
| </> | ||
| )} | ||
| </> | ||
| ); | ||
|
|
||
|
|
@@ -55,8 +91,15 @@ const Header = () => { | |
| <IcLogo className={styles.logoImage} /> | ||
| </Link> | ||
|
|
||
| {renderNavMenu()} | ||
| {isLoggedIn ? ( | ||
| renderNavMenu() | ||
| ) : ( | ||
| <button className={styles.loginButton} onClick={handleLogin}> | ||
| 로그인 | ||
| </button> | ||
| )} | ||
| </div> | ||
| {ModalWrapper} | ||
| </header> | ||
| ); | ||
| }; | ||
|
|
||
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.
p3) 여기서 env 직접 읽지 말고 authConstants.ts의 GOOGLE_REDIRECT_URI를 재사용해서 환경값을 한 곳에서 관리하면 좋을 것 같아요 !!
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.
그렇네요 ..! 수정했습니다 !!