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:
31
test-fe-api.js
Normal file
31
test-fe-api.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function test() {
|
||||
const login = await axios.post('http://localhost:3000/api/auth/login', {
|
||||
email: 'admin@contentgen.ai',
|
||||
password: 'Admin123!',
|
||||
});
|
||||
const token = login.data.data.accessToken;
|
||||
|
||||
// Simulate interceptor
|
||||
let responseData = await axios.get('http://localhost:3000/api/projects', {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
}).then(r => {
|
||||
let data = r.data;
|
||||
if (data && typeof data === 'object' && 'success' in data && 'data' in data) {
|
||||
data = data.data;
|
||||
}
|
||||
return data;
|
||||
});
|
||||
|
||||
console.log("Interceptor Output:", JSON.stringify(responseData, null, 2).substring(0, 500));
|
||||
|
||||
const raw = responseData;
|
||||
const rawProjects = raw?.data ?? raw ?? [];
|
||||
const projects = Array.isArray(rawProjects) ? rawProjects : [];
|
||||
|
||||
console.log("Is array?", Array.isArray(rawProjects));
|
||||
console.log("Projects length:", projects.length);
|
||||
}
|
||||
|
||||
test();
|
||||
Reference in New Issue
Block a user