diff --git a/app/create-news/page.tsx b/app/create-news/page.tsx index 9edd6a7..85e7dc9 100644 --- a/app/create-news/page.tsx +++ b/app/create-news/page.tsx @@ -1,15 +1,47 @@ "use client"; -import React, { useState, useRef } from 'react'; +import React, { useState, useRef, useEffect } from 'react'; import Image from 'next/image'; import { LayoutDashboard, Newspaper, Users, BarChart3, Settings, HelpCircle, Image as ImageIcon, Type, Calendar, Clock, Tag, User, Save, Eye, Send } from 'lucide-react'; +import Keycloak from "keycloak-js"; // Importe o componente que criámos (ajuste o caminho se necessário) import MultiAspectEditor from '../components/MultiAspectEditor'; -import { Editor } from '@tinymce/tinymce-react'; +import dynamic from "next/dynamic"; +const Editor = dynamic( + () => import("@tinymce/tinymce-react").then((mod) => mod.Editor), + { ssr: false } +); + +const keycloak = new Keycloak({ + url: "https://keycloak.petermaquiran.xyz", + realm: "tvone", // ✅ IMPORTANT + clientId: "tvone-web", // must match Keycloak client +}); + +interface GoogleAuthResponse { + access_token: string; + token_type: string; + expires_in: number; + scope: string; + authuser?: string; + prompt?: string; +} + +interface KeycloakTokenResponse { + access_token: string; + expires_in: number; + refresh_expires_in: number; + refresh_token: string; + token_type: string; + id_token?: string; + "not-before-policy": number; + session_state: string; + scope: string; +} const CreateNewsPage = () => { @@ -76,6 +108,26 @@ const CreateNewsPage = () => { fileInputRef.current?.click(); }; + // Avoid hydration mismatch by waiting for mount + useEffect(() => { + keycloak.init({ + onLoad: "check-sso", // or "login-required" + pkceMethod: "S256", + }).then((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/", { + headers: { + Authorization: `Bearer ${localStorage.getItem("token")}`, + }, + }); + } + }); + }, []); + return (
diff --git a/app/login/page.tsx b/app/login/page.tsx index dacbad5..97c4337 100644 --- a/app/login/page.tsx +++ b/app/login/page.tsx @@ -197,7 +197,7 @@ export default function AppleStyleAuth() { {/* 4. BOTÃO GOOGLE */}