Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_BACKEND_URL=http://localhost:5000 || "";
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
52 changes: 5 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@tailwindcss/vite": "^4.3.1",
"axios": "^1.18.0",
"axios": "^1.19.0",
"lucide-react": "^1.21.0",
"react": "^19.2.7",
"react-dom": "^19.2.7",
Expand Down
40 changes: 40 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import axios from "axios";
import { error } from "console";
import { config } from "process";

const BACKEND_URL = import.meta.env.VITE_BACKEND_URL;

const api = axios.create({
baseURL: BACKEND_URL,
headers: {
"Content-Type": "application/json",
},
});

//request interceptor-token irntha attach pannum

api.interceptors.request.use(
(config) => {
const token = localStorage.getItem("token");
if (token) {
config.headers.Authorization = `Bearer${token}`;
}
return config;
},
(error) => Promise.reject(error),
);

// Response interceptor-common error handling

api.interceptors.request.use(
(response) => response,
(error) => {
if (error.response.status === 400) {
// token expire aayiducha,logout logic ingayum podalam
localStorage.removeItem("token");
}
return Promise.reject(error);
},
);

export default api;