From d1d999f2a7c2f22d3169ace091d4ec77fc7b6446 Mon Sep 17 00:00:00 2001 From: peintnermax Date: Wed, 24 Jan 2024 16:27:13 +0100 Subject: [PATCH] reload userinfo --- src/App.tsx | 4 ++-- src/components/Callback.tsx | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8ac2d78..450d580 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,8 +9,8 @@ import Callback from "./components/Callback"; function App() { const config: ZitadelConfig = { - issuer: "", - client_id: "", + issuer: "https://maxsecond-ekvdou.zitadel.cloud/", + client_id: "251008059999082377@react", }; const zitadel = createZitadelAuth(config); diff --git a/src/components/Callback.tsx b/src/components/Callback.tsx index 4446c92..a6aa815 100644 --- a/src/components/Callback.tsx +++ b/src/components/Callback.tsx @@ -19,8 +19,34 @@ const Callback = ({ handleLogout, }: Props) => { useEffect(() => { - if (authenticated === null || userInfo === null) { - userManager() + if (authenticated === null) { + userManager + .signinRedirectCallback() + .then((user: any) => { + if (user) { + setAuth(true); + const access_token = user.access_token; + const userInfoEndpoint = `${issuer}oidc/v1/userinfo`; + fetch(userInfoEndpoint, { + headers: { + Authorization: `Bearer ${access_token}`, + }, + }) + .then((response) => response.json()) + .then((userInfo) => { + setUserInfo(userInfo); + }); + } else { + setAuth(false); + } + }) + .catch((error: any) => { + setAuth(false); + }); + } + if (authenticated === true && userInfo === null) { + userManager + .getUser() .then((user: any) => { if (user) { setAuth(true);