Skip to content
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

[Refactor/#402] 로컬 스토리지의 role 여부에 따라, 저장된 로그인 여부 clear 하도록 수정 #403

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/apis/domains/users/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export const usePostKakaoLogin = () => {
const userData = response;

if (userData) {
const { accessToken, nickname } = userData;
const { accessToken, nickname, role } = userData;

if (accessToken && nickname) {
setUserData({ nickname, accessToken });
setUserData({ nickname, accessToken, role });
} else {
console.error("accessToken or nickname is undefined");
}
Expand Down
15 changes: 11 additions & 4 deletions src/hooks/useTokenRefresher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ export default function TokenRefresher() {
const navigate = useNavigate();
const { openAlert } = useModal();

const user = localStorage.getItem("user");
if (user) {
if (!JSON.parse(user)?.role) {
// 기존에 존재하던 유저 role 유무로 임시로 토큰 제거 후 리로드
localStorage.clear();
window.location.reload();
return;
}
Comment on lines +11 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

p5) 굿굿 깔끔하네요 ~~

Copy link
Contributor

Choose a reason for hiding this comment

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

p5 ) 진심 최고.......

}

useEffect(() => {
const interceptor = instance.interceptors.response.use(
// 성공적인 응답 처리
Expand Down Expand Up @@ -64,11 +74,8 @@ export default function TokenRefresher() {
}
} else if (status === 400 || status === 404 || status === 409) {
} else if (status === 500) {
// role 변경으로 임시로 500 에러시 토큰 제거
localStorage.clear();
openAlert({
title: "토큰이 만료되었습니다. \n다시 로그인 해주세요.",
okCallback: () => window.location.reload(),
title: "서버에 문제가 발생했습니다. 잠시 후 다시 시도해주세요.",
});
}
// 다른 모든 오류를 거부하고 처리
Expand Down
1 change: 1 addition & 0 deletions src/stores/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import { atomWithStorage } from "jotai/utils";
export const userAtom = atomWithStorage<UserProps>("user", {
nickname: "",
accessToken: "",
role: "",
});
Loading
Loading