From 9269d293967077a04f6fa304769d37152110ebf5 Mon Sep 17 00:00:00 2001 From: yoonyesol Date: Tue, 3 Sep 2024 17:16:16 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20#80=20URL=20revoke=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=B0=8F=20=ED=8C=8C=EC=9D=BC=20=EA=B2=BD=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=8B=9C=EA=B0=84=20=EC=83=81=EC=88=98=20?= =?UTF-8?q?=ED=99=9C=EC=9A=A9=20=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/auth-form/ProfileImageContainer.tsx | 14 +++++--------- src/constants/settings.ts | 8 ++++---- src/mocks/handlers.ts | 2 +- src/services/axiosProvider.ts | 4 ++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/components/user/auth-form/ProfileImageContainer.tsx b/src/components/user/auth-form/ProfileImageContainer.tsx index b65e6e5d..b599ff73 100644 --- a/src/components/user/auth-form/ProfileImageContainer.tsx +++ b/src/components/user/auth-form/ProfileImageContainer.tsx @@ -4,7 +4,7 @@ import { useFormContext } from 'react-hook-form'; import { convertBytesToString } from '@utils/converter'; import { USER_SETTINGS } from '@constants/settings'; import useToast from '@hooks/useToast'; -import { useEffect, useRef } from 'react'; +import { useEffect } from 'react'; type ProfileImageContainerProps = { imageUrl: string; @@ -14,14 +14,12 @@ type ProfileImageContainerProps = { export default function ProfileImageContainer({ imageUrl, setImageUrl }: ProfileImageContainerProps) { const { setValue } = useFormContext(); const { toastWarn } = useToast(); - const imageRef = useRef(null); - // 컴포넌트 언마운트 시 이미지 URL 해제 useEffect(() => { return () => { - if (imageRef.current) URL.revokeObjectURL(imageRef.current); + if (imageUrl) URL.revokeObjectURL(imageUrl); }; - }, []); + }, [imageUrl]); const handleChangeImg = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; @@ -37,13 +35,11 @@ export default function ProfileImageContainer({ imageUrl, setImageUrl }: Profile const image = URL.createObjectURL(file); setImageUrl(image); setValue('profileUrl', image); - imageRef.current = image; }; const handleRemoveImg = () => { - if (imageRef.current) { - URL.revokeObjectURL(imageRef.current); - imageRef.current = null; + if (imageUrl) { + URL.revokeObjectURL(imageUrl); } setImageUrl(''); diff --git a/src/constants/settings.ts b/src/constants/settings.ts index e74320f1..75573579 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -1,9 +1,9 @@ -import { MB } from '@constants/units'; +import { DAY, MB, MINUTE, SECOND } from '@constants/units'; export const AUTH_SETTINGS = Object.freeze({ - // ACCESS_TOKEN_EXPIRATION: 3000, // 테스트용 3초 - ACCESS_TOKEN_EXPIRATION: 15 * 60 * 1000, // 15분 - REFRESH_TOKEN_EXPIRATION: 7 * 24 * 60 * 60 * 1000, // 7일 + // ACCESS_TOKEN_EXPIRATION: 5 * SECOND, // 테스트용 5초 + ACCESS_TOKEN_EXPIRATION: 15 * MINUTE, // 15분 + REFRESH_TOKEN_EXPIRATION: 7 * DAY, // 7일 }); export const USER_SETTINGS = Object.freeze({ diff --git a/src/mocks/handlers.ts b/src/mocks/handlers.ts index a9884e73..1aae7d61 100644 --- a/src/mocks/handlers.ts +++ b/src/mocks/handlers.ts @@ -2,7 +2,7 @@ import userServiceHandler from '@mocks/services/userServiceHandler'; import teamServiceHandler from '@mocks/services/teamServiceHandler'; import projectServiceHandler from '@mocks/services/projectServiceHandler'; import taskServiceHandler from '@mocks/services/taskServiceHandler'; -import authServiceHandler from './services/authServiceHandler'; +import authServiceHandler from '@mocks/services/authServiceHandler'; const handlers = [ ...userServiceHandler, diff --git a/src/services/axiosProvider.ts b/src/services/axiosProvider.ts index 87f5e0f6..bcd7ea19 100644 --- a/src/services/axiosProvider.ts +++ b/src/services/axiosProvider.ts @@ -2,9 +2,9 @@ import axios from 'axios'; import { SECOND } from '@constants/units'; import { JWT_TOKEN_DUMMY } from '@mocks/mockData'; import type { AxiosInstance, AxiosRequestConfig } from 'axios'; +import useToast from '@hooks/useToast'; +import { getAccessToken } from '@services/authService'; import { useAuthStore } from '@/stores/useAuthStore'; -import useToast from '@/hooks/useToast'; -import { getAccessToken } from './authService'; const BASE_URL = import.meta.env.VITE_BASE_URL; const defaultConfigOptions: AxiosRequestConfig = {