diff --git a/app/(page)/create-news/page.tsx b/app/(page)/create-news/page.tsx index 7426db5..94d425e 100644 --- a/app/(page)/create-news/page.tsx +++ b/app/(page)/create-news/page.tsx @@ -6,30 +6,16 @@ import { 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 dynamic from "next/dynamic"; +import { keycloak } from '@/app/feature/auth/keycloak-config'; 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; @@ -131,8 +117,16 @@ const CreateNewsPage = () => { const profile = await res.json(); - setUser(profile); - console.log("Profile:", profile); + var keycloakData : { + email: string, + email_verified: boolean, + name: string, + picture: string, + roles: string[] + } = profile.keycloak + + setUser(keycloakData); + console.log("Profile:", keycloakData); } }); }, []); diff --git a/app/(page)/login/page.tsx b/app/(page)/login/page.tsx index 6514c20..8d53ba7 100644 --- a/app/(page)/login/page.tsx +++ b/app/(page)/login/page.tsx @@ -4,14 +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 "keycloak-js"; - - -const keycloak = new Keycloak({ - url: "https://keycloak.petermaquiran.xyz", - realm: "tvone", // ✅ IMPORTANT - clientId: "tvone-web", // must match Keycloak client -}); +import { keycloak } from '@/app/feature/auth/keycloak-config'; interface GoogleAuthResponse { access_token: string; diff --git a/app/feature/auth/keycloak-config.ts b/app/feature/auth/keycloak-config.ts index 6dc0824..a7388b2 100644 --- a/app/feature/auth/keycloak-config.ts +++ b/app/feature/auth/keycloak-config.ts @@ -1,3 +1,5 @@ +import Keycloak from "keycloak-js"; + /** * KEYCLOAK CONFIGURATION * Logic: Environment variable validation and OIDC configuration. @@ -13,9 +15,15 @@ export const keycloakConfig = { // Endpoint for global logout endSessionEndpoint: `${process.env.KEYCLOAK_ISSUER_URL}/realms/${process.env.KEYCLOAK_REALM}/protocol/openid-connect/logout`, - }; +}; - // Simple check to ensure environment variables are present - if (!process.env.KEYCLOAK_CLIENT_ID || !process.env.KEYCLOAK_ISSUER_URL) { +// Simple check to ensure environment variables are present +if (!process.env.KEYCLOAK_CLIENT_ID || !process.env.KEYCLOAK_ISSUER_URL) { console.warn("Auth Warning: Keycloak environment variables are missing."); - } \ No newline at end of file +} + +export const keycloak = new Keycloak({ + url: "https://keycloak.petermaquiran.xyz", + realm: "tvone", // ✅ IMPORTANT + clientId: "tvone-web", // must match Keycloak client +}); \ No newline at end of file