chore: jwt token in frontend
Browse files- 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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;
|