From 2595ada98299fe44aab696843b31ef7f52178087 Mon Sep 17 00:00:00 2001 From: yws1502 Date: Sat, 23 Nov 2024 12:22:06 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20#275=20-=20401=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=B0=9C=EC=83=9D=20=EC=8B=9C=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EB=A9=94=EC=86=8C=EB=93=9C=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/axios.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/axios.ts b/src/lib/axios.ts index bd576a92..c3236b4f 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; From 9f8b8d2a0e5f83d9a50d25eec1e8a9c7134eb871 Mon Sep 17 00:00:00 2001 From: yws1502 Date: Sun, 24 Nov 2024 20:54:41 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=9A=B8=20#275=20-=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=8B=A4=ED=8C=A8=20=EC=8B=9C=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/validation/message.ts | 2 ++ src/pages/account/login.tsx | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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/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) {