Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/packages/teleport/src/Login/Login.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const sample: State = {
isSuccess: true,
message: '',
},
checkingValidSession: false,
onLogin: () => null,
onLoginWithWebauthn: () => null,
onLoginWithSso: () => null,
Expand Down
7 changes: 7 additions & 0 deletions web/packages/teleport/src/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function Login({
onLoginWithSso,
authProviders,
auth2faType,
checkingValidSession,
preferredMfaType,
isLocalAuthEnabled,
clearAttempt,
Expand All @@ -47,6 +48,12 @@ export function Login({
showMotd,
acknowledgeMotd,
}: State) {
// while we are checking if a session is valid, we don't return anything
// to prevent flickering. The check only happens for a frame or two so
// we avoid rendering a loader/indicator since that will flicker as well
if (checkingValidSession) {
return null;
}
return (
<>
<Logo src={logoSrc} />
Expand Down
13 changes: 12 additions & 1 deletion web/packages/teleport/src/Login/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useAttempt } from 'shared/hooks';
import { AuthProvider } from 'shared/services';

import session from 'teleport/services/websession';
import history from 'teleport/services/history';
import cfg from 'teleport/config';
import auth, { UserCredentials } from 'teleport/services/auth';

export default function useLogin() {
const [attempt, attemptActions] = useAttempt({ isProcessing: false });
const [checkingValidSession, setCheckingValidSession] = useState(true);

const authProviders = cfg.getAuthProviders();
const auth2faType = cfg.getAuth2faType();
Expand All @@ -44,6 +46,14 @@ export default function useLogin() {
setShowMotd(false);
}

useEffect(() => {
if (session.isValid()) {
history.replace(cfg.routes.root);
return;
}
setCheckingValidSession(false);
}, []);

function onLogin(email, password, token) {
attemptActions.start();
auth
Expand Down Expand Up @@ -74,6 +84,7 @@ export default function useLogin() {
return {
attempt,
onLogin,
checkingValidSession,
onLoginWithSso,
authProviders,
auth2faType,
Expand Down