mirror of
https://github.com/PeterMaquiran/tvone.git
synced 2026-04-18 15:27:52 +00:00
This commit is contained in:
@@ -89,6 +89,11 @@ const CreateNewsPage = () => {
|
||||
const [isEditorOpen, setIsEditorOpen] = useState(false);
|
||||
const [finalCrops, setFinalCrops] = useState<any>(null); // Guarda os Base64 finais
|
||||
const [content, setContent] = useState('');
|
||||
const [user, setUser] = useState<{
|
||||
email?: string;
|
||||
name?: string;
|
||||
picture?: string;
|
||||
} | null>(null);
|
||||
|
||||
const fileInputRef = useRef<HTMLInputElement>(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);
|
||||
const token = keycloak.token!;
|
||||
localStorage.setItem("token", token);
|
||||
|
||||
fetch("http://localhost:3001/profile/", {
|
||||
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 = () => {
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<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>
|
||||
</div>
|
||||
<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>
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user