mirror of
https://github.com/PeterMaquiran/tvone.git
synced 2026-04-18 07:17:52 +00:00
This commit is contained in:
+22
-10
@@ -89,6 +89,11 @@ const CreateNewsPage = () => {
|
|||||||
const [isEditorOpen, setIsEditorOpen] = useState(false);
|
const [isEditorOpen, setIsEditorOpen] = useState(false);
|
||||||
const [finalCrops, setFinalCrops] = useState<any>(null); // Guarda os Base64 finais
|
const [finalCrops, setFinalCrops] = useState<any>(null); // Guarda os Base64 finais
|
||||||
const [content, setContent] = useState('');
|
const [content, setContent] = useState('');
|
||||||
|
const [user, setUser] = useState<{
|
||||||
|
email?: string;
|
||||||
|
name?: string;
|
||||||
|
picture?: string;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
@@ -111,19 +116,23 @@ const CreateNewsPage = () => {
|
|||||||
// Avoid hydration mismatch by waiting for mount
|
// Avoid hydration mismatch by waiting for mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
keycloak.init({
|
keycloak.init({
|
||||||
onLoad: "check-sso", // or "login-required"
|
onLoad: "check-sso",
|
||||||
pkceMethod: "S256",
|
pkceMethod: "S256",
|
||||||
}).then((authenticated) => {
|
}).then(async (authenticated) => {
|
||||||
if (authenticated) {
|
if (authenticated) {
|
||||||
localStorage.setItem("token", keycloak.token!);
|
const token = keycloak.token!;
|
||||||
console.log("Logged in", keycloak.token);
|
localStorage.setItem("token", token);
|
||||||
localStorage.setItem("token", keycloak.token as string);
|
|
||||||
|
const res = await fetch("http://localhost:3001/profile/", {
|
||||||
fetch("http://localhost:3001/profile/", {
|
|
||||||
headers: {
|
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 = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<div className="text-right">
|
<div className="text-right">
|
||||||
<p className="text-xs font-bold">James Wilson</p>
|
<p className="text-xs font-bold">{user?.name ?? "Loading..."}</p>
|
||||||
<p className="text-[10px] text-slate-500">Editor</p>
|
<p className="text-[10px] text-slate-500">Editor</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-8 h-8 bg-slate-300 rounded-full border border-white shadow-sm overflow-hidden">
|
<div className="w-8 h-8 bg-slate-300 rounded-full border border-white shadow-sm overflow-hidden">
|
||||||
<img src="https://ui-avatars.com/api/?name=James+Wilson" alt="User" />
|
<img
|
||||||
|
src={user?.picture ?? "https://ui-avatars.com/api/?name=User"}
|
||||||
|
alt="User"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
Reference in New Issue
Block a user