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:
@@ -27,17 +27,21 @@ export function ContentTable() {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const fetchContent = useCallback(async () => {
|
const fetchContent = useCallback(async () => {
|
||||||
if (!session?.accessToken) return;
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
|
const headers: HeadersInit = {};
|
||||||
|
if (session?.accessToken) {
|
||||||
|
headers['Authorization'] = `Bearer ${session.accessToken}`;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await fetch('/api/backend/content', {
|
const res = await fetch('/api/backend/content', {
|
||||||
headers: {
|
headers,
|
||||||
'Authorization': `Bearer ${session.accessToken}`
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const responseData = await res.json();
|
||||||
setContentList(Array.isArray(data) ? data : []);
|
// Handle wrapped response from global interceptor: { success, data, message }
|
||||||
|
const items = responseData?.data || responseData;
|
||||||
|
setContentList(Array.isArray(items) ? items : []);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch content:", error);
|
console.error("Failed to fetch content:", error);
|
||||||
|
|||||||
Reference in New Issue
Block a user