Skip to content

Commit 185d477

Browse files
authored
fix(fe): update axios interceptor (#232)
fix: update axios interceptor to use PostRefreshResponseDTO for token handling
1 parent 34e3863 commit 185d477

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

apps/client/src/shared/axios.config.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios from 'axios';
22

33
import { useAuthStore } from '@/features/auth';
4+
import { PostRefreshResponseDTO } from '@/features/auth/auth.dto';
45

56
axios.interceptors.request.use(
67
(config) => {
@@ -28,17 +29,15 @@ axios.interceptors.response.use(
2829
credentials: 'include',
2930
});
3031

31-
const { type, data: result } = (await response.json()) as {
32-
type: 'success' | 'fail';
33-
data: { accessToken: string };
34-
};
32+
const { accessToken, userId } =
33+
(await response.json()) as PostRefreshResponseDTO;
3534

3635
const { setAuthInformation, clearAuthInformation } =
3736
useAuthStore.getState();
3837

39-
if (type === 'success' && result.accessToken) {
40-
setAuthInformation(result);
41-
originalRequest.headers.Authorization = `Bearer ${result.accessToken}`;
38+
if (accessToken) {
39+
setAuthInformation({ accessToken, userId });
40+
originalRequest.headers.Authorization = `Bearer ${accessToken}`;
4241
return axios(originalRequest);
4342
}
4443

0 commit comments

Comments
 (0)