From 4aaaa4e33bb1fc8695c0be32466d7cdb151afd9a Mon Sep 17 00:00:00 2001 From: bottlewook Date: Thu, 7 Mar 2024 17:05:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20request=20interceptor=20id=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(auth)/login/page.tsx | 10 +--------- src/remote/api/instance.api.ts | 8 +++++--- src/remote/queries/auth/useLogin.ts | 1 + 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index ef335831..99c248bf 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -28,7 +28,7 @@ const cx = classNames.bind(styles); function LoginPage() { const { register, handleSubmit, formState: { isValid } } = useForm(); - const { mutate, isError, isSuccess } = useLogin(); + const { mutate, isError } = useLogin(); const onSubmit = (data: ISignIn) => { const { @@ -39,14 +39,6 @@ function LoginPage() { }); }; - /* -- redux test -- */ - const userId = useAppSelector((state) => { return state.user.id; }); - // console.log(userId); - - if (isSuccess) { - console.log(userId); - } - return ( <>
diff --git a/src/remote/api/instance.api.ts b/src/remote/api/instance.api.ts index 5ed76f9a..c44122cc 100644 --- a/src/remote/api/instance.api.ts +++ b/src/remote/api/instance.api.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-param-reassign */ import { toast } from 'react-toastify'; import axios, { @@ -21,13 +22,14 @@ export const instance: Axios = axios.create({ instance.interceptors.request.use( (config: InternalAxiosRequestConfig): InternalAxiosRequestConfig => { /** - * request 직전 공통으로 진행할 작업 - */ + * request 직전 공통으로 진행할 작업 + */ const token = getCookie('token') as string; + const id = getCookie('id') as string; if (config && config.headers) { if (token) { - // eslint-disable-next-line no-param-reassign config.headers.Authorization = token; + config.headers.id = id; } } if (process.env.NODE_ENV === 'development') { diff --git a/src/remote/queries/auth/useLogin.ts b/src/remote/queries/auth/useLogin.ts index 4ec77731..8ba1992e 100644 --- a/src/remote/queries/auth/useLogin.ts +++ b/src/remote/queries/auth/useLogin.ts @@ -16,6 +16,7 @@ function useLogin() { const cookieOptions = { path: '/', maxAge: 60 * 15 }; setCookie('token', jwtToken, cookieOptions); + setCookie('id', id, cookieOptions); dispatch(setUserId({ id, email })); router.push('/'); };