From 4e7794476b7f35edca20e464913479dda7683a4b Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 17 Apr 2026 10:48:36 +0100 Subject: [PATCH] login with gmail with keyclock --- app/login/page.tsx | 20 +++++++++++++++++++- package.json | 1 + pnpm-lock.yaml | 8 ++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/login/page.tsx b/app/login/page.tsx index 1a710f4..9aae938 100644 --- a/app/login/page.tsx +++ b/app/login/page.tsx @@ -4,6 +4,14 @@ 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 +}); interface GoogleAuthResponse { access_token: string; @@ -34,6 +42,16 @@ export default function AppleStyleAuth() { // 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); + } + }); setMounted(true); }, []); @@ -173,7 +191,7 @@ export default function AppleStyleAuth() { {/* 4. BOTÃO GOOGLE */}