Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/auth/googleLogin/authConstants.ts
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';
3 changes: 2 additions & 1 deletion src/api/auth/googleLogin/util/getAccessToken.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import axiosInstance from '@/api/axiosInstance';

const getAccessToken = async (code: string) => {
const redirectUri = import.meta.env.VITE_GOOGLE_REDIRECT_URI;
const redirectUri = import.meta.env.VITE_GOOGLE_REDIRECT_URI_LOCAL;
Copy link
Copy Markdown
Contributor

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를 재사용해서 환경값을 한 곳에서 관리하면 좋을 것 같아요 !!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네요 ..! 수정했습니다 !!


const response = await axiosInstance.post(
`/auth/oauth2/google/callback?redirect_uri=${redirectUri}`,
{ code },
);

return response.data.data;
};

Expand Down
3 changes: 3 additions & 0 deletions src/api/domain/signup/hook/useGetUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { getUser } from '@/api/domain/signup';
import { QUERY_KEY } from '@/api/constant/queryKey';

export const useGetUser = () => {
const token = localStorage.getItem('accessToken');

return useQuery({
queryKey: QUERY_KEY.USER_INFO,
queryFn: getUser,
enabled: !!token,
});
};
2 changes: 1 addition & 1 deletion src/common/component/UserModal/UserModal.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const profileContainer = style({
export const profileImage = style({
width: '5rem',
height: '5rem',
borderRadius: '25%',
borderRadius: '50%',
objectFit: 'cover',
});

Expand Down
11 changes: 7 additions & 4 deletions src/page/home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNavigate } from 'react-router-dom';

Check failure on line 1 in src/page/home/Home.tsx

View workflow job for this annotation

GitHub Actions / build

'useNavigate' is declared but its value is never read.

import { HomeContainer } from '@/page/home/Home.css';
import { INTRO_MESSAGE } from '@/page/home/constant/scrollSection';
Expand All @@ -10,19 +10,21 @@
import { useMultipleFadeInOnView } from '@/page/home/hook/useMultipleFadeInOnView';
import mandalAnimation from '@/assets/lottie/mandalart.json';
import aiAnimation from '@/assets/lottie/ai.json';
import { PATH } from '@/route';
import todoAnimation from '@/assets/lottie/todo.json';
import { useModal } from '@/common/hook/useModal';
import LoginModal from '@/common/component/LoginModal/LoginModal';

const animationDataArray = [mandalAnimation, aiAnimation, todoAnimation];
const sectionKeys = ['mandalart', 'ai', 'todo'] as const;

const Home = () => {
const navigate = useNavigate();
const scrolls = useMultipleFadeInOnView();
const end = useFadeInOnView<HTMLDivElement>();

const { openModal, closeModal, ModalWrapper } = useModal();

const handleOpenLogin = () => {
// openModal(<LoginModal onClose={closeModal} />);
navigate(PATH.TODO);
openModal(<LoginModal onClose={closeModal} />);
};

return (
Expand All @@ -44,6 +46,7 @@
})}

<EndSection fadeInRef={end.ref} visible={end.visible} onClick={handleOpenLogin} />
{ModalWrapper}
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/shared/component/Layout/layoutHeader/Header.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const profilePlaceholder = style({
borderRadius: '50%',
backgroundColor: colors.grey6,
flexShrink: 0,
cursor: 'pointer',
});

export const loginButton = style({
Expand Down
47 changes: 45 additions & 2 deletions src/shared/component/Layout/layoutHeader/Header.tsx
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 },
Expand All @@ -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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p1) 여기서 setIsLoggedIn(true)가 바로 실행돼서 로그인 성공 여부랑 상관없이 로그인 상태로 전환되고 있는 것 같아요.
지금 로그인 모달 열리고 바깥 영역 클릭해서 닫으면 로그인 버튼이 유지되는데 X 버튼으로 닫으면 로그인 버튼이 사라지고 메뉴들이 나오는데 요거 해결이 필요해 보입니당


const handleMenuClick = (menuLabel: string, path: string) => {
setActiveMenu(menuLabel);
navigate(path);
};

const handleProfile = () => {
setOpenProfile((prev) => !prev);
};

const renderNavMenu = () => (
<>
<nav className={styles.navWrapper}>
Expand All @@ -45,6 +70,17 @@ const Header = () => {
);
})}
</nav>
{!isLoading && user && (
<>
<img
src={user.profileImageUrl}
alt="유저 프로필"
className={styles.profilePlaceholder}
onClick={handleProfile}
/>
{openProfile && <UserModal onClose={handleProfile} />}
</>
)}
</>
);

Expand All @@ -55,8 +91,15 @@ const Header = () => {
<IcLogo className={styles.logoImage} />
</Link>

{renderNavMenu()}
{isLoggedIn ? (
renderNavMenu()
) : (
<button className={styles.loginButton} onClick={handleLogin}>
로그인
</button>
)}
</div>
{ModalWrapper}
</header>
);
};
Expand Down
Loading