first ugly version of authenticated backend requests.

needs some refactoring, but it works?
This commit is contained in:
2025-06-30 13:22:27 +02:00
parent d9050b35ba
commit ca378790f1
6 changed files with 52 additions and 2 deletions
+1
View File
@@ -8,6 +8,7 @@ Log.setLogger(console);
export default function Page() {
const auth = useAuth();
console.log(auth);
switch (auth.activeNavigator) {
case "signinSilent":
+31
View File
@@ -0,0 +1,31 @@
"use client";
import { getUser } from "muzak/data/fetch";
import { useEffect, useState } from "react";
export default function Page() {
const [userData, setUserData] = useState<User[]>([]);
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);
}
getUsers();
}, []);
return (
<div className="flex min-h-screen flex-col items-center justify-around">
{userData.length > 0 ? (
userData.map((user) => <div key={user.id}>{user.email}</div>)
) : (
<div>Loading users...</div>
)}
</div>
);
}