Skip to content

Commit

Permalink
fix(api.js): when get user is called using api and there is no email,…
Browse files Browse the repository at this point in the history
… sign user out #19
  • Loading branch information
junglesub committed Aug 5, 2024
1 parent b411fa3 commit 275a1c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/pages/NewUser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ function NewUser() {
// User Already have profile
useEffect(() => {
if (!jwtValue) return;
fetchBe(jwtValue, "/userDetail/get")
.then((json) => {
// 기존 사용자
setUserData(json);
setUserInputState((prev) => ({
...prev,
height: json.height || null,
weight: json.weight || null,
}));
})
.catch((e) => setUserDataError(e.message));
fetchBe(jwtValue, "/userDetail/get").then((json) => {
// 기존 사용자
setUserData(json);
setUserInputState((prev) => ({
...prev,
height: json.height || null,
weight: json.weight || null,
}));
});
fetchBe(jwtValue, "/user/get").then(({ nickName }) => {
if (nickName) {
setNicknameState({
Expand Down
2 changes: 1 addition & 1 deletion src/tools/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const fetchBe = (jwtValue, path, method = "GET", body) =>
.then((doc) =>
doc.json().then((json) => {
// If User not exist (due to db reset, etc)
if (json?.message?.includes('"user" is null')) {
if (path === "/user/get" && !json?.email) {
alert("유저가 존재하지 않습니다. 로그인을 다시해주세요.");
localStorage.clear();
window.location.reload();
Expand Down

0 comments on commit 275a1c1

Please sign in to comment.