Skip to content

Commit

Permalink
Add busy waiting for username state to update
Browse files Browse the repository at this point in the history
  • Loading branch information
iyannsch committed Nov 5, 2024
1 parent 5ec8bc2 commit f88d18c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion node/landing-page/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,28 @@ function App(): JSX.Element {
if (auth) {
const parsedToken = keycloak.idTokenParsed;
if (parsedToken) {
// Only finish initialization after the username was set successfully (used in automatic session start)
const userMail = parsedToken.email;
setToken(keycloak.idToken);
setEmail(userMail);
setUsername(parsedToken.preferred_username ?? userMail);
setLogoutUrl(keycloak.createLogoutUrl());
while (username !== (parsedToken.preferred_username ?? userMail)) {
// Wait for the username to be set
}
initialized = true;
console.log('Authenticated as ' + parsedToken.preferred_username + '(' + userMail + ')');
console.log(username);
}
}
})
.catch(() => {
console.error('Authentication Failed');
});
} else {
// Finish initialization if no keycloak is used
initialized = true;
}
initialized = true;
}

useEffect(() => {
Expand Down

0 comments on commit f88d18c

Please sign in to comment.