generated from fahricansecer/boilerplate-fe
Some checks failed
UI Deploy (Next-Auth Support) 🎨 / build-and-deploy (push) Has been cancelled
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import axios from 'axios';
|
|
|
|
// Bu bir simulasyon, frontend API klientinin nasil calistigini gosterecek.
|
|
const client = axios.create({ baseURL: 'http://localhost:3000/api' });
|
|
client.interceptors.response.use(
|
|
(response) => {
|
|
if (
|
|
response.data &&
|
|
typeof response.data === 'object' &&
|
|
'success' in response.data &&
|
|
'data' in response.data
|
|
) {
|
|
response.data = response.data.data;
|
|
}
|
|
return response;
|
|
}
|
|
);
|
|
|
|
async function test() {
|
|
const loginRes = await axios.post('http://localhost:3000/api/auth/login', {
|
|
email: 'admin@contentgen.ai',
|
|
password: 'Admin123!'
|
|
});
|
|
const token = loginRes.data.accessToken;
|
|
|
|
if (!token) {
|
|
console.log("No token");
|
|
return;
|
|
}
|
|
|
|
client.interceptors.request.use((config) => {
|
|
config.headers['Authorization'] = `Bearer ${token}`;
|
|
return config;
|
|
});
|
|
|
|
const res = await client.get('/projects?limit=100');
|
|
const rData = res.data;
|
|
console.log("rData structure:", typeof rData, Object.keys(rData));
|
|
|
|
const raw = rData;
|
|
const rawProjects = raw?.data ?? raw ?? [];
|
|
const projects = Array.isArray(rawProjects) ? rawProjects : [];
|
|
|
|
console.log("Final extracted projects count:", projects.length);
|
|
}
|
|
|
|
test().catch(console.error);
|