generated from fahricansecer/boilerplate-fe
main
Some checks failed
UI Deploy (Next-Auth Support) 🎨 / build-and-deploy (push) Has been cancelled
Some checks failed
UI Deploy (Next-Auth Support) 🎨 / build-and-deploy (push) Has been cancelled
This commit is contained in:
47
test-frontend-useProjects.js
Normal file
47
test-frontend-useProjects.js
Normal file
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
Reference in New Issue
Block a user