diff --git a/src/constants/validation/message.ts b/src/constants/validation/message.ts index b0318e18..bb0f8ee5 100644 --- a/src/constants/validation/message.ts +++ b/src/constants/validation/message.ts @@ -18,6 +18,8 @@ export const ERROR_MESSAGE = { length: '6~30자 이내로 입력해주세요.', pattern: '영어, 숫자, 특수문자 중 최소 2가지를 조합해주세요.', invalidPattern: '사용할 수 없는 문자입니다.', + failed: + '아이디 또는 비밀번호가 잘못 되었습니다. 아이디와 비밀번호를 정확히 입력해주세요.', }, passwordCheck: { required: '비밀번호를 확인해주세요.', diff --git a/src/lib/axios.ts b/src/lib/axios.ts index bd576a92..43985789 100644 --- a/src/lib/axios.ts +++ b/src/lib/axios.ts @@ -1,5 +1,5 @@ -import axios from 'axios'; -import { getSession } from 'next-auth/react'; +import axios, { isAxiosError } from 'axios'; +import { getSession, signOut } from 'next-auth/react'; import type { AxiosRequestConfig } from 'axios'; const options: AxiosRequestConfig = { @@ -25,4 +25,19 @@ client.interceptors.request.use( async (error) => await Promise.reject(error), ); +client.interceptors.response.use( + (response) => { + return response; + }, + (error) => { + if (isAxiosError(error) && error.response?.status === 401) { + alert('접속 시간이 만료되었습니다.\n로그인 후 다시 이용해주세요.'); + void signOut(); + return; + } + + return Promise.reject(error); + }, +); + export default client; diff --git a/src/pages/account/login.tsx b/src/pages/account/login.tsx index 8573633c..e6cb1f34 100644 --- a/src/pages/account/login.tsx +++ b/src/pages/account/login.tsx @@ -45,7 +45,7 @@ const Login: NextPage = () => { }); setError('password', { type: 'exist', - message: response?.error, + message: ERROR_MESSAGE.password.failed, }); } if (response?.ok === true) {