Skip to content

Commit

Permalink
axios interceptors 사용하여 Authorization 헤더에 자동으로 토큰추가
Browse files Browse the repository at this point in the history
  • Loading branch information
leesh7048 committed Aug 26, 2024
1 parent 18c99c6 commit bd4fbc9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@ const instance = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL,
});

instance.interceptors.request.use(
(config) => {
const token = localStorage.getItem("accessToken");

if (token) {
config.headers.Authorization = `Bearer ${token}`;
}

return config;
},
(error) => {
return Promise.reject(error);
}
);

export default instance;

0 comments on commit bd4fbc9

Please sign in to comment.