Skip to content

Commit

Permalink
๐Ÿ›  fix : ๋กœ๊ทธ์ธ ๋กœ๊ทธ์•„์›ƒ ๋ฐ”๋กœ ๋ฐ˜์˜ ์•ˆ๋˜๋Š” ์˜ค๋ฅ˜
Browse files Browse the repository at this point in the history
  • Loading branch information
seondal committed Apr 2, 2024
1 parent b566199 commit bdc7398
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 29 deletions.
7 changes: 7 additions & 0 deletions src/apis/config/privateApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ privateApi.interceptors.request.use(
return config;
},
(error) => {
alert('์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”!');
location.href = '/auth/logout';
// if (error.response.status === 415) {
// if (confirm('์„ธ์…˜์ด ๋งŒ๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋กœ๊ทธ์ธํ•ด์ฃผ์„ธ์š”!')) {
// open('/menu');
// }
// }
return Promise.reject(error);
}
);
Expand Down
3 changes: 1 addition & 2 deletions src/app/(Main)/mypose/components/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ interface LoginModalProps {

export default function LoginModal({ onClose }: LoginModalProps) {
const router = useRouter();

const handleLogin = () => {
router.push(KAKAO_AUTHORIZE);
router.replace(KAKAO_AUTHORIZE);
};

return (
Expand Down
7 changes: 6 additions & 1 deletion src/app/(Main)/mypose/components/LoginSection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import LoginModal from './LoginModal';
import LogoutModal from './LogoutModal';
import { Icon } from '@/components/Button/Icon';
import { useOverlay } from '@/components/Overlay/useOverlay';
import { ICON } from '@/constants/icon';
Expand All @@ -22,7 +23,11 @@ export default function LoginSection() {
<section className="py-24">
<button
className="flex w-full items-center gap-16"
onClick={() => !isLogin && open(() => <LoginModal onClose={exit} />)}
onClick={() =>
isLogin
? open(({ exit }) => <LogoutModal exit={exit} />)
: open(() => <LoginModal onClose={exit} />)
}
>
<DefaultProfile />
<div className="text-start">
Expand Down
25 changes: 25 additions & 0 deletions src/app/(Main)/mypose/components/LogoutModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use client';

import { useRouter } from 'next/navigation';

import { PrimaryButton } from '@/components/Button';
import { Popup } from '@/components/Modal';

export default function LogoutModal({ exit }: { exit(): void }) {
const router = useRouter();
return (
<Popup
title="๋กœ๊ทธ์•„์›ƒ"
content={`๋ถ๋งˆํฌ๋Š” ๋กœ๊ทธ์ธ ์‹œ์—๋งŒ ์œ ์ง€๋˜์–ด์š”.\n์ •๋ง ๋กœ๊ทธ์•„์›ƒํ•˜์‹œ๊ฒ ์–ด์š”?`}
>
<>
<PrimaryButton
text={'๋กœ๊ทธ์•„์›ƒ'}
type="secondary"
onClick={() => router.push('/auth/logout')}
/>
<PrimaryButton text="๋กœ๊ทธ์ธ ์œ ์ง€" onClick={exit} />
</>
</Popup>
);
}
21 changes: 2 additions & 19 deletions src/app/(Sub)/menu/MenuListSection.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
'use client';

import Link from 'next/link';
import { useRouter } from 'next/navigation';

import { PrimaryButton } from '@/components/Button';
import { Popup } from '@/components/Modal';
import LogoutModal from '@/app/(Main)/mypose/components/LogoutModal';
import { useOverlay } from '@/components/Overlay/useOverlay';
import { menuList } from '@/constants/data';
import useUserState from '@/context/userState';

export default function MenuListSection() {
const { isLogin } = useUserState();
const { open } = useOverlay();
const router = useRouter();

function handleLogout() {
open(({ exit }) => (
<Popup
title="๋กœ๊ทธ์•„์›ƒ"
content={`๋ถ๋งˆํฌ๋Š” ๋กœ๊ทธ์ธ ์‹œ์—๋งŒ ์œ ์ง€๋˜์–ด์š”.\n์ •๋ง ๋กœ๊ทธ์•„์›ƒํ•˜์‹œ๊ฒ ์–ด์š”?`}
>
<>
<PrimaryButton
text={'๋กœ๊ทธ์•„์›ƒ'}
type="secondary"
onClick={() => router.replace('/auth/logout')}
/>
<PrimaryButton text="๋กœ๊ทธ์ธ ์œ ์ง€" onClick={exit} />
</>
</Popup>
));
open(({ exit }) => <LogoutModal exit={exit} />);
}

return (
Expand Down
8 changes: 4 additions & 4 deletions src/app/auth/logout/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { patchLogout } from '@/apis';
import useUserState from '@/context/userState';

export default function Page() {
const router = useRouter();
const { token, clearUser } = useUserState();
const router = useRouter();

useEffect(() => {
if (token) {
patchLogout(token.accessToken, token.refreshToken).then((response) => {
patchLogout(token.accessToken, token.refreshToken).then(() => {
alert('๋กœ๊ทธ์•„์›ƒ ์„ฑ๊ณต!');
localStorage.removeItem('accesstoken');
});
}
clearUser();
router.replace('/menu');
localStorage.removeItem('accesstoken');
router.back();
});

return <>๋กœ๊ทธ์•„์›ƒ</>;
Expand Down
4 changes: 2 additions & 2 deletions src/app/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import useUserState from '@/context/userState';

export default function Page() {
const code = useSearchParams().get('code');
const router = useRouter();
const { setUser } = useUserState();
const router = useRouter();

useEffect(() => {
if (code) {
getRegister(code).then((response) => {
setUser(response);
localStorage.setItem('accesstoken', response.token.accessToken);
alert(`๋กœ๊ทธ์ธ์— ์„ฑ๊ณตํ–ˆ์–ด์š”!`);
router.back();
router.replace('/mypose/bookmark');
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/context/userState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function useUserState() {

const setUser = (data: RegisterResponse) => {
setUserAtom(data);
console.log(data.email + '๋‹˜ ๋กœ๊ทธ์ธ ์„ฑ๊ณต');
console.log(data.email);
};
const clearUser = () => setUserAtom(null);

Expand Down

0 comments on commit bdc7398

Please sign in to comment.