From 7854e3dd448c8bf6ecd672012b31da65299c7786 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 17 Apr 2026 16:15:00 +0100 Subject: [PATCH] show profile picture and name --- app/create-news/page.tsx | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/app/create-news/page.tsx b/app/create-news/page.tsx index 85e7dc9..f194b09 100644 --- a/app/create-news/page.tsx +++ b/app/create-news/page.tsx @@ -89,6 +89,11 @@ const CreateNewsPage = () => { const [isEditorOpen, setIsEditorOpen] = useState(false); const [finalCrops, setFinalCrops] = useState(null); // Guarda os Base64 finais const [content, setContent] = useState(''); + const [user, setUser] = useState<{ + email?: string; + name?: string; + picture?: string; + } | null>(null); const fileInputRef = useRef(null); @@ -111,19 +116,23 @@ const CreateNewsPage = () => { // Avoid hydration mismatch by waiting for mount useEffect(() => { keycloak.init({ - onLoad: "check-sso", // or "login-required" + onLoad: "check-sso", pkceMethod: "S256", - }).then((authenticated) => { + }).then(async (authenticated) => { if (authenticated) { - localStorage.setItem("token", keycloak.token!); - console.log("Logged in", keycloak.token); - localStorage.setItem("token", keycloak.token as string); - - fetch("http://localhost:3001/profile/", { + const token = keycloak.token!; + localStorage.setItem("token", token); + + const res = await fetch("http://localhost:3001/profile/", { headers: { - Authorization: `Bearer ${localStorage.getItem("token")}`, + Authorization: `Bearer ${token}`, }, }); + + const profile = await res.json(); + + setUser(profile); + console.log("Profile:", profile); } }); }, []); @@ -187,11 +196,14 @@ const CreateNewsPage = () => {
-

James Wilson

+

{user?.name ?? "Loading..."}

Editor

- User + User