Add client code directly

This commit is contained in:
Mohan Ki
2026-07-27 13:42:31 +05:30
parent 60dcb029dc
commit 40667e54ac
51 changed files with 10035 additions and 1 deletions
+28
View File
@@ -0,0 +1,28 @@
import axios from 'axios';
const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4001/api',
withCredentials: true,
headers: {
'Content-Type': 'application/json',
},
});
// Add a request interceptor to attach JWT token
api.interceptors.request.use(
(config) => {
// We only access localStorage in the browser
if (typeof window !== 'undefined') {
const token = localStorage.getItem('token');
if (token && config.headers) {
config.headers.Authorization = `Bearer ${token}`;
}
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
export default api;