Skip to content

Commit 59ae588

Browse files
committed
fix: header 토큰 재로그인시 갱신
1 parent c925c66 commit 59ae588

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

app/lib/reactQueryProvider.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ import { getLoginInfo, removeAccessToken } from "@/utils/localStorage";
99
import { useIsLoggedInWrite } from "@/components/atoms/account.atom";
1010
import { useSnackBarWrite } from "@/components/atoms/snackBar.atom";
1111

12-
const { accessToken } = getLoginInfo();
13-
1412
export const apiClient = axios.create({
1513
withCredentials: true,
16-
headers: {
17-
...(accessToken && {
18-
Authorization: `Bearer ${accessToken.replace(/^"(.*)"$/, "$1")}`,
19-
}),
20-
},
2114
});
2215

16+
apiClient.interceptors.request.use(
17+
(config) => {
18+
const { accessToken } = getLoginInfo();
19+
20+
if (accessToken) {
21+
config.headers.Authorization = `Bearer ${accessToken.replace(/^"(.*)"$/, "$1")}`;
22+
}
23+
24+
return config;
25+
},
26+
(error) => Promise.reject(error)
27+
);
28+
2329
type ErrorResponse = {
2430
response: {
2531
data: {

0 commit comments

Comments
 (0)