Skip to content

Commit

Permalink
Merge pull request #17 from local-mood/Hyeonmin
Browse files Browse the repository at this point in the history
Feat:로그아웃 로직 생성
  • Loading branch information
wokbjso authored Dec 24, 2023
2 parents ebe97db + 4ce6f93 commit b5c3cb8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
57 changes: 42 additions & 15 deletions src/common/layout/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,61 @@ import AuthButton from "../../ui/buttons/AuthButton/AuthButton";
import theme from "@/styles/theme";
import { useNavigate } from "react-router-dom";
import useBlurWhenScroll from "@/common/hooks/useBlurWhenScroll";
import { useGetMemberInfo } from "@/features/member/queries/useGetMemberInfo";
import { useQueryClient } from "@tanstack/react-query";
export default function Header() {
const navigate = useNavigate();
const queryClient = useQueryClient();
const { ref } = useBlurWhenScroll();
const { user } = useGetMemberInfo();
const navigateLogin = () => {
navigate("/login");
};
const navigateRegister = () => {
navigate("/register");
};
const logoutClicked = () => {
if (window.confirm("로그아웃 하시겠습니까?")) {
alert("로그아웃 되었습니다.");
localStorage.removeItem("token");
queryClient.invalidateQueries({
queryKey: ["getMemberInfo"],
});
queryClient.clear();
navigate("/");
}
};
return (
<HeaderLayout ref={ref}>
<HeaderText />
<HeaderBtn>
<AuthButton
width="9.6rem"
bgColor={theme.colors.white}
addClass="margin-right:2rem;"
onClick={navigateLogin}
>
로그인
</AuthButton>
<AuthButton
width="11.4rem"
bgColor={theme.colors.mainColor}
onClick={navigateRegister}
>
회원가입
</AuthButton>
{!user ? (
<>
<AuthButton
width="9.6rem"
bgColor={theme.colors.white}
addClass="margin-right:2rem;"
onClick={navigateLogin}
>
로그인
</AuthButton>
<AuthButton
width="11.4rem"
bgColor={theme.colors.mainColor}
onClick={navigateRegister}
>
회원가입
</AuthButton>
</>
) : (
<AuthButton
width="11.4rem"
bgColor={theme.colors.mainColor}
onClick={logoutClicked}
>
로그아웃
</AuthButton>
)}
</HeaderBtn>
</HeaderLayout>
);
Expand Down
1 change: 0 additions & 1 deletion src/features/auth/queries/usePostLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ async function postLogin(data: AuthLoginRequest) {
"/app/auth/login",
data
);
console.log(data);
return res.data.data.accessToken;
}

Expand Down
2 changes: 0 additions & 2 deletions src/pages/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { usePostLogin } from "@/features/auth/queries/usePostLogin";
import { LoginFormState } from "@/features/form/states/form-data-state";
import { useEffect } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { useNavigate } from "react-router-dom";

export default function Login() {
const queryClient = useQueryClient();
const navigate = useNavigate();
const { mutate: postLogin, data: token } = usePostLogin();
const { isMobile } = MediaQuery();
const loginFormSubmit = (e: LoginFormState) => {
Expand Down

0 comments on commit b5c3cb8

Please sign in to comment.