Skip to content

Commit

Permalink
feat: request interceptor id 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bottlewook committed Mar 7, 2024
1 parent e31dc32 commit 4aaaa4e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
10 changes: 1 addition & 9 deletions src/app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const cx = classNames.bind(styles);

function LoginPage() {
const { register, handleSubmit, formState: { isValid } } = useForm<ISignIn>();
const { mutate, isError, isSuccess } = useLogin();
const { mutate, isError } = useLogin();

const onSubmit = (data: ISignIn) => {
const {
Expand All @@ -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 (
<>
<Header />
Expand Down
8 changes: 5 additions & 3 deletions src/remote/api/instance.api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
import { toast } from 'react-toastify';

import axios, {
Expand All @@ -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') {
Expand Down
1 change: 1 addition & 0 deletions src/remote/queries/auth/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
};
Expand Down

0 comments on commit 4aaaa4e

Please sign in to comment.