diff --git a/app/(page)/create-news/page.tsx b/app/(page)/create-news/page.tsx index 94d425e..11cc2e0 100644 --- a/app/(page)/create-news/page.tsx +++ b/app/(page)/create-news/page.tsx @@ -10,7 +10,7 @@ import { // Importe o componente que criámos (ajuste o caminho se necessário) import MultiAspectEditor from '../../components/MultiAspectEditor'; import dynamic from "next/dynamic"; -import { keycloak } from '@/app/feature/auth/keycloak-config'; +// import { keycloak } from '@/app/feature/auth/keycloak-config'; const Editor = dynamic( () => import("@tinymce/tinymce-react").then((mod) => mod.Editor), { ssr: false } @@ -100,36 +100,43 @@ const CreateNewsPage = () => { }; // Avoid hydration mismatch by waiting for mount - useEffect(() => { - keycloak.init({ - onLoad: "check-sso", - pkceMethod: "S256", - }).then(async (authenticated) => { - if (authenticated) { - const token = keycloak.token!; - localStorage.setItem("token", token); - - const res = await fetch("http://localhost:3001/profile/", { - headers: { - Authorization: `Bearer ${token}`, - }, - }); - - const profile = await res.json(); - - var keycloakData : { - email: string, - email_verified: boolean, - name: string, - picture: string, - roles: string[] - } = profile.keycloak + // useEffect(() => { + // keycloak.init({ + // onLoad: "check-sso", + // pkceMethod: "S256", + // }).then(async (authenticated) => { + // if (authenticated) { + // const token = keycloak.token!; + // localStorage.setItem("token", token); - setUser(keycloakData); - console.log("Profile:", keycloakData); - } - }); - }, []); + // // 👉 send token to Next.js backend + // fetch("/api/session", { + // method: "POST", + // body: JSON.stringify({ token }), + // }); + + + // const res = await fetch("http://localhost:3001/profile/", { + // headers: { + // //Authorization: `Bearer ${token}`, + // }, + // }); + + // const profile = await res.json(); + + // var keycloakData : { + // email: string, + // email_verified: boolean, + // name: string, + // picture: string, + // roles: string[] + // } = profile.keycloak + + // setUser(keycloakData); + // console.log("Profile:", keycloakData); + // } + // }); + // }, []); return (
diff --git a/app/(page)/login/page.tsx b/app/(page)/login/page.tsx index 8d53ba7..30da652 100644 --- a/app/(page)/login/page.tsx +++ b/app/(page)/login/page.tsx @@ -4,7 +4,7 @@ import React, { useState, useEffect } from "react"; import { useGoogleLogin } from "@react-oauth/google"; import { useTheme } from 'next-themes'; import { Sun, Moon } from 'lucide-react'; // Optional: install lucide-react for clean icons -import { keycloak } from '@/app/feature/auth/keycloak-config'; +//import { keycloak } from '@/app/feature/auth/keycloak-config'; interface GoogleAuthResponse { access_token: string; @@ -33,27 +33,6 @@ export default function AppleStyleAuth() { const { theme, setTheme } = useTheme(); const [mounted, setMounted] = useState(false); - // 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")}`, - }, - }); - } - }); - setMounted(true); - }, []); - const handleExchange = async (googleResponse: GoogleAuthResponse): Promise => { try { const details: Record = { @@ -190,11 +169,7 @@ export default function AppleStyleAuth() { {/* 4. BOTÃO GOOGLE */}