Skip to content

Commit

Permalink
refactor: (#508) hasEssentialInfo을 쿠키가 아닌 로컬스토리지로 변경
Browse files Browse the repository at this point in the history
유효 기간이 없다는 장점과 보안과 상관없는 정보이기 때문에 Secure, HttpOnly 설정이 필요 없어보여서 로컬 스토리지로 변경
  • Loading branch information
Gilpop8663 committed Sep 4, 2023
1 parent c642498 commit ce217d4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import PostOptionProvider from '@hooks/context/postOption';

import router from '@routes/router';

import ChannelTalk from '@pages/ChannelTalk';
import ErrorBoundaryForTopClass from '@pages/ErrorBoundaryForTopClass';

import ChannelTalk from '@components/ChannelTalk';

import { GlobalStyle } from '@styles/globalStyle';
import { theme } from '@styles/theme';

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/common/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Suspense, useContext } from 'react';
import { useNavigate } from 'react-router-dom';

import { AuthContext } from '@hooks/context/auth';

Expand All @@ -13,11 +14,14 @@ import * as S from './style';
import UserProfile from './UserProfile';

export default function Dashboard() {
const navigate = useNavigate();
const { loggedInfo, clearLoggedInfo } = useContext(AuthContext);
const { userInfo } = loggedInfo;

const handleLogoutClick = () => {
clearLoggedInfo();

navigate('/');
};

return (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/context/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
const clearLoggedInfo = () => {
clearCookieToken('accessToken');
clearCookieToken('refreshToken');
clearCookieToken('hasEssentialInfo');
localStorage.removeItem('hasEssentialInfo');

setLoggedInfo(notLoggedInfo);
};
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/MyInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export default function MyInfo() {
useEffect(() => {
if (isWithdrawalMembershipSuccess) {
clearLoggedInfo();

navigate('/');
}
}, [isWithdrawalMembershipSuccess, clearLoggedInfo, navigate]);
}, [isWithdrawalMembershipSuccess]);

useEffect(() => {
if (isWithdrawalMembershipError && withdrawalMembershipError instanceof Error) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/auth/Redirection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function Redirection() {
const { accessToken, hasEssentialInfo, refreshToken } = await getAuthInfo(REGISTER_API_URL);
setCookieToken('accessToken', accessToken);
setCookieToken('refreshToken', refreshToken ?? '');
setCookieToken('hasEssentialInfo', String(hasEssentialInfo));
localStorage.setItem('hasEssentialInfo', String(hasEssentialInfo));

const decodedPayload = decodeToken(accessToken);
const id = decodedPayload.memberId;
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/pages/user/RegisterPersonalInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import SquareButton from '@components/common/SquareButton';

import { BIRTH_YEAR } from '@constants/user';

import { setCookieToken } from '@utils/cookie';

import * as S from './style';

interface UserInfoForm {
Expand Down Expand Up @@ -62,7 +60,7 @@ export default function RegisterPersonalInfo() {

const submittedUserInfo = { gender, birthYear: Number(birthYear) };
updateUserInfo(submittedUserInfo);
setCookieToken('hasEssentialInfo', 'true');
localStorage.setItem('hasEssentialInfo', 'true');

alert('개인 정보 등록 완료!');
navigate('/');
Expand Down

0 comments on commit ce217d4

Please sign in to comment.