aki-008 commited on
Commit
d5c13b8
·
1 Parent(s): 657674a

chore: jwt token in frontend

Browse files
Files changed (1) hide show
  1. Frontend/src/api/api.ts +12 -1
Frontend/src/api/api.ts CHANGED
@@ -4,4 +4,15 @@ const API = axios.create({
4
  baseURL: "http://localhost:8000/api/v1",
5
  });
6
 
7
- export default API;
 
 
 
 
 
 
 
 
 
 
 
 
4
  baseURL: "http://localhost:8000/api/v1",
5
  });
6
 
7
+ // Attach token automatically for every request
8
+ API.interceptors.request.use((config) => {
9
+ const token = localStorage.getItem("token");
10
+
11
+ if (token) {
12
+ config.headers.Authorization = Bearer ${token};
13
+ }
14
+
15
+ return config;
16
+ });
17
+
18
+ export default API;