initial: standalone repo from monorepo split

This commit is contained in:
kevin-asprec
2026-04-13 09:36:30 +08:00
commit e3fead36d5
19 changed files with 597 additions and 0 deletions

25
src/lib/api.ts Normal file
View File

@@ -0,0 +1,25 @@
import axios from 'axios';
export const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001/api/portal',
headers: { 'Content-Type': 'application/json' },
});
api.interceptors.request.use((config) => {
if (typeof window !== 'undefined') {
const token = localStorage.getItem('portalToken');
if (token) config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
api.interceptors.response.use(
(r) => r,
(error) => {
if (error.response?.status === 401 && typeof window !== 'undefined') {
localStorage.removeItem('portalToken');
window.location.href = '/login';
}
return Promise.reject(error);
},
);