first version of data fetcher

This commit is contained in:
2025-07-19 10:50:41 +02:00
parent 041333d1da
commit ef0f82d516
4 changed files with 107 additions and 9 deletions
+4 -9
View File
@@ -1,20 +1,15 @@
"use client";
import { getUser } from "muzak/data/fetch";
import { useEffect, useState } from "react";
import api from "muzak/data/fetcher";
export default function Page() {
const [userData, setUserData] = useState<User[]>([]);
const [userData, setUserData] = useState([]);
useEffect(() => {
async function getUsers() {
const user = getUser();
const access_token = user?.access_token;
const headers = new Headers();
headers.set("Authorization", `Bearer ${access_token}`);
headers.set("Content-Type", "application/json; charset=utf-8");
const users = await fetch("http://127.0.0.1:8001/api/user/", { headers });
const userData = await users.json();
setUserData(userData);
const { data: users } = await api.users.list({});
setUserData(users);
}
getUsers();
}, []);