Skip to content

Commit

Permalink
reload userinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
peintnermax committed Jan 24, 2024
1 parent 7f8f54b commit d1d999f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 28 additions & 2 deletions src/components/Callback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d1d999f

Please sign in to comment.