Skip to content

Commit

Permalink
[Fix]로그인 유지안되는 오류 해결
Browse files Browse the repository at this point in the history
이메일로 로그인 시 로컬스토리지에 저장되는 토큰의 키 이름 변경
Issues #15
  • Loading branch information
김병현 authored and 김병현 committed Sep 15, 2023
1 parent 80ef822 commit 424b30b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions client/src/components/Logins/EmailLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const EmailLoginModal: React.FC<EmailLoginModalProps> = ({ onClose, onLogin }) =
dispatch(setLoginState());

// 토큰들을 로컬 스토리지에 저장
if (authToken) localStorage.setItem("authToken", authToken);
if (refreshToken) localStorage.setItem("refreshToken", refreshToken);
if (authToken) localStorage.setItem("Authorization", authToken);
if (refreshToken) localStorage.setItem("Refresh-token", refreshToken);

onLogin();
onClose();
Expand Down
22 changes: 10 additions & 12 deletions client/src/page/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const MainPage = () => {

const dispatch = useDispatch();
const isLogin = useSelector((state: RootState) => state.login);
console.log(isLogin);

// 🔴 페이지 로드 시 로컬 스토리지의 토큰을 기반으로 로그인 상태를 확인합니다.
useEffect(() => {
Expand All @@ -119,18 +120,15 @@ const MainPage = () => {
dispatch(setLoginState());
};

// // 🔴 로그아웃 시 로컬스토리지에 있는 Auth 토큰 제거
// const handleLogout = () => {
// dispatch(setLogoutState());
// localStorage.removeItem("Authorization");
// };

const handleLoginConfirmationClose = () => {
setLoginConfirmationModalOpen(false);
};

// 현재 선택된 메뉴 타입을 상태로 관리
const [selectedMenu, setSelectedMenu] = useState<"전체종목" | "관심종목" | "보유종목">("전체종목");

// 메뉴 변경 핸들러
const handleMenuChange = (menu: "전체종목" | "관심종목" | "보유종목") => {
setSelectedMenu(menu);
};
Expand All @@ -146,13 +144,13 @@ const MainPage = () => {
<CompareChartSection />
{!expandScreen.left && (
<LeftSection>
{selectedMenu === "전체종목" ? (
<EntireList key="entirelist" currentListType={selectedMenu} onChangeListType={handleMenuChange} />
) : selectedMenu === "보유종목" ? (
<HoldingList key="holdinglist" currentListType={selectedMenu} onChangeListType={handleMenuChange} />
) : (
<WatchList key="watchlist" currentListType={selectedMenu} onChangeListType={handleMenuChange} />
)}
{selectedMenu === "전체종목" ? (
<EntireList currentListType={selectedMenu} onChangeListType={handleMenuChange} />
) : selectedMenu === "관심종목" ? (
<WatchList currentListType={selectedMenu} onChangeListType={handleMenuChange} />
) : selectedMenu === "보유종목" ? (
<HoldingList currentListType={selectedMenu} onChangeListType={handleMenuChange} />
) : null}
</LeftSection>
)}
<CentralChart />
Expand Down

0 comments on commit 424b30b

Please sign in to comment.