Skip to content

Commit

Permalink
Feat: Authorization 조건부 삽입 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
LeHiHo committed Jan 4, 2024
1 parent 81e0853 commit 1b26218
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import axios from 'axios';

const accessToken = window.localStorage.getItem('accessToken');
let accessToken;
if (window.localStorage.getItem('accessToken')) {
accessToken = window.localStorage.getItem('accessToken');
}

// axios 인스턴스를 생성합니다.
const client = axios.create({
baseURL: import.meta.env.VITE_SERVER_URL,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
},
withCredentials: true,
});
Expand Down

0 comments on commit 1b26218

Please sign in to comment.