diff --git a/src/api/index.ts b/src/api/index.ts
deleted file mode 100644
index add34953..00000000
--- a/src/api/index.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import axios from 'axios';
-import { HTTP_BASE_URL } from '../constants/api';
-
-export const instance = axios.create({
- baseURL: HTTP_BASE_URL,
-});
diff --git a/src/api/index.tsx b/src/api/index.tsx
new file mode 100644
index 00000000..db3046be
--- /dev/null
+++ b/src/api/index.tsx
@@ -0,0 +1,85 @@
+import axios from 'axios';
+import { HTTP_BASE_URL, HTTP_STATUS_CODE } from '../constants/api';
+import { getCookie, removeCookie, setCookie } from '@hooks/sign-in/useSignIn';
+import { message } from 'antd';
+import { TextBox } from '@components/text-box';
+import { ROUTES } from '@/constants/routes';
+
+export const instance = axios.create({
+ baseURL: HTTP_BASE_URL,
+ headers: {
+ 'Content-Type': 'application/json',
+ timeout: 5000,
+ },
+});
+
+instance.interceptors.request.use(
+ (config) => {
+ const accessToken = getCookie('accessToken');
+ if (accessToken) {
+ config.headers['Authorization'] = `Bearer ${accessToken}`;
+ }
+ return config;
+ },
+ (error) => {
+ return Promise.reject(error);
+ },
+);
+
+instance.interceptors.response.use(
+ (response) => {
+ if (response.status === HTTP_STATUS_CODE.NOTFOUND) {
+ // 콘솔 지우고 바로 404 페이지로 넘어가게 할 예정
+ console.log('404 페이지로 넘어가야 함!');
+ }
+ return response;
+ },
+ async (error) => {
+ const accessToken = getCookie('accessToken');
+ if (window.location.pathname !== ROUTES.SIGNIN && !accessToken) {
+ message.error({
+ content: (
+
+ accessToken이 없습니다.
+
+ ),
+ duration: 2,
+ });
+ removeCookie('accessToken');
+ removeCookie('refreshToken');
+ removeCookie('accommodationId');
+ setTimeout(() => {
+ window.location.href = ROUTES.SIGNIN;
+ }, 1000);
+ return Promise.reject(error);
+ } else if (
+ window.location.pathname !== ROUTES.SIGNIN &&
+ error.response.status === HTTP_STATUS_CODE.UNAUTHORIZED
+ ) {
+ try {
+ // 여기에 재발급 api 선언, 아래는 예시
+ const newAccessToken = 'ivegaeul';
+ setCookie('accessToken', newAccessToken);
+ return axios(error.config);
+ } catch (refreshError) {
+ removeCookie('accessToken');
+ removeCookie('refreshToken');
+ removeCookie('accommodationId');
+ message.error({
+ content: (
+
+ 로그인 만료입니다.
+
+ ),
+ duration: 2,
+ });
+ setTimeout(() => {
+ window.location.href = ROUTES.SIGNIN;
+ }, 1000);
+ return Promise.reject(refreshError);
+ }
+ }
+ },
+);
+
+export default instance;
diff --git a/src/api/sign-in/index.ts b/src/api/sign-in/index.ts
index f1ad0806..925541cd 100644
--- a/src/api/sign-in/index.ts
+++ b/src/api/sign-in/index.ts
@@ -5,7 +5,7 @@ import { Response } from '@/types/api';
export const SIGN_IN_API = {
postLogin: (data: SignInData) =>
- instance.post>('/api/auth/owner/signin', {
+ instance.post>('/api/auth/owners/signin', {
data,
}),
};
diff --git a/src/mocks/handlers.ts b/src/mocks/handlers.ts
index 80244505..9d628c9d 100644
--- a/src/mocks/handlers.ts
+++ b/src/mocks/handlers.ts
@@ -32,7 +32,7 @@ const email = 'ivegaeul@naver.com';
const verificationCode = '020924';
const accommodationId = 1;
export const handlers = [
- http.post('/api/auth/owner/signin', postSignInResolver),
+ http.post('/api/auth/owners/signin', postSignInResolver),
http.post('/api/auth/owners/signup', postSignUpResolver),
http.post('/api/auth/owners/request-email', postAuthenticationResolver),
http.get(
diff --git a/src/pages/sign-in-agreement/index.tsx b/src/pages/sign-in-agreement/index.tsx
index f549ed99..1d9be8ce 100644
--- a/src/pages/sign-in-agreement/index.tsx
+++ b/src/pages/sign-in-agreement/index.tsx
@@ -9,6 +9,7 @@ import { colors } from '@/constants/colors';
export const SignInAgreement = () => {
const { handleChangeUrl } = useCustomNavigate();
+ const [allChecked, setAllChecked] = useState(false);
const [isChecked, setIsChecked] = useState([]);
const [isDisabled, setIsDisabled] = useState(true);
const data = [
@@ -33,11 +34,15 @@ export const SignInAgreement = () => {
const handleSingleCheck = (checked: boolean, id: number) => {
if (checked) {
setIsChecked((prev) => [...prev, id]);
+ if (isChecked.length + 1 === 4) {
+ setAllChecked(true);
+ }
if (id === 0) {
setIsDisabled(false);
}
} else {
setIsChecked(isChecked.filter((el) => el !== id));
+ setAllChecked(false);
if (id === 0) {
setIsDisabled(true);
}
@@ -50,11 +55,14 @@ export const SignInAgreement = () => {
data.forEach((el) => idArray.push(el.id));
setIsChecked(idArray);
setIsDisabled(false);
+ setAllChecked(true);
} else {
setIsChecked([]);
setIsDisabled(true);
+ setAllChecked(false);
}
};
+
return (
@@ -82,7 +90,11 @@ export const SignInAgreement = () => {
-
+
diff --git a/src/pages/sign-up/index.tsx b/src/pages/sign-up/index.tsx
index 4e8324ef..87d538ab 100644
--- a/src/pages/sign-up/index.tsx
+++ b/src/pages/sign-up/index.tsx
@@ -21,6 +21,7 @@ export const SignUp = () => {
const [checkOne, setCheckOne] = useState(false);
const [checkOne_1, setCheckOne_1] = useState(false);
const [checkOne_2, setCheckOne_2] = useState(false);
+ const [checkOne_3, setCheckOne_3] = useState(false);
const [checkTwo, setCheckTwo] = useState(false);
const [checkTwo_1, setCheckTwo_1] = useState(false);
const [checkThree, setCheckThree] = useState(false);
@@ -55,20 +56,28 @@ export const SignUp = () => {
setCheckOne(true);
setCheckOne_1(false);
setCheckOne_2(false);
+ setCheckOne_3(false);
setEmailDisabled(true);
},
onError: (error: unknown) => {
if (error instanceof AxiosError && error.response) {
const errorData = error.response.data;
if (errorData) {
- if (errorData.code == RESPONSE_CODE.INCORRECT_EMAIL_CODE) {
+ if (errorData.code === RESPONSE_CODE.INCORRECT_EMAIL_CODE) {
setCheckOne(false);
setCheckOne_1(true);
setCheckOne_2(false);
- } else {
+ setCheckOne_3(false);
+ } else if (errorData.code === RESPONSE_CODE.REQUEST_BODY_ERROR) {
setCheckOne(false);
setCheckOne_1(false);
setCheckOne_2(true);
+ setCheckOne_3(false);
+ } else {
+ setCheckOne(false);
+ setCheckOne_1(false);
+ setCheckOne_2(false);
+ setCheckOne_3(true);
}
}
}
@@ -134,6 +143,7 @@ export const SignUp = () => {
setVerifyError(true);
}
};
+
useEffect(() => {
if (touched.password && errors.password) {
setCheckThree(false);
@@ -251,6 +261,16 @@ export const SignUp = () => {
)}
{checkOne_2 && (
+
+ 이메일 형식이 올바르지 않습니다.
+
+ )}
+ {checkOne_3 && (