Skip to content

Commit

Permalink
Add more logic to authenticate the user before launching the appDef
Browse files Browse the repository at this point in the history
  • Loading branch information
iyannsch committed Oct 29, 2024
1 parent 97e6c64 commit 3d0873d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions node/landing-page/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import { Loading } from './components/Loading';
import { LoginButton } from './components/LoginButton';

// global state to be kept between render calls
let initialized = false;
let initialAppName = '';
let initialAppDefinition = '';
let keycloakConfig: KeycloakConfig | undefined = undefined;

function App(): JSX.Element {
const [initialized, setInitialized] = useState(false);
const [config] = useState(() => getTheiaCloudConfig());
const [error, setError] = useState<string>();
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -124,14 +124,15 @@ function App(): JSX.Element {
setToken(keycloak.idToken);
setEmail(userMail);
setLogoutUrl(keycloak.createLogoutUrl());
setInitialized(true);
}
}
})
.catch(() => {
console.error('Authentication Failed');
setError('Authentication failed');
});
}
initialized = true;
}

useEffect(() => {
Expand All @@ -150,8 +151,7 @@ function App(): JSX.Element {
}

if (selectedAppDefinition && gitUri) {
console.log('Checking auth, setting autoStart to true and starting session');
authenticate();
console.log('Setting autoStart to true and starting session');
setAutoStart(true);
handleStartSession(selectedAppDefinition);
} else {
Expand All @@ -165,6 +165,7 @@ function App(): JSX.Element {

document.title = `${selectedAppName} - Theia`;


const authenticate = (): void => {
const keycloak = Keycloak(keycloakConfig);
keycloak
Expand Down Expand Up @@ -197,6 +198,7 @@ function App(): JSX.Element {
setLoading(true);
setError(undefined);


// first check if the service is available. if not we are doing maintenance and should adapt the error message accordingly
TheiaCloud.ping(PingRequest.create(config.serviceUrl, config.appId))
.then(() => {
Expand Down Expand Up @@ -296,6 +298,7 @@ function App(): JSX.Element {
'Sorry, we are performing some maintenance at the moment.\n' +
"Please try again later. Usually maintenance won't last longer than 60 minutes.\n\n"
);
setError(_err.message);
setLoading(false);
});
};
Expand Down

0 comments on commit 3d0873d

Please sign in to comment.