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);