From 7fb7c4817a642e30b34f81a14fd30dc02542c45f Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Thu, 26 Aug 2021 16:23:04 -0400 Subject: [PATCH] feat(login): auto-retry login with existing credentials --- src/app/Login/Login.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app/Login/Login.tsx b/src/app/Login/Login.tsx index 901039e0d..24a889d52 100644 --- a/src/app/Login/Login.tsx +++ b/src/app/Login/Login.tsx @@ -39,8 +39,8 @@ import * as React from 'react'; import { ServiceContext } from '@app/Shared/Services/Services'; import { useSubscriptions } from '@app/utils/useSubscriptions'; import { Card, CardBody, CardFooter, CardHeader, PageSection, Title } from '@patternfly/react-core'; -import { timer } from 'rxjs'; -import { first } from 'rxjs/operators'; +import { combineLatest, timer } from 'rxjs'; +import { debounceTime, first } from 'rxjs/operators'; import { Base64 } from 'js-base64'; import { BasicAuthDescriptionText, BasicAuthForm } from './BasicAuthForm'; import { BearerAuthDescriptionText, BearerAuthForm } from './BearerAuthForm'; @@ -82,6 +82,21 @@ export const Login = (props) => { return () => sub.unsubscribe(); }, [context, context.api, setAuthMethod, checkAuth]); + React.useEffect(() => { + const sub = + combineLatest(context.api.getToken(), context.api.getAuthMethod(), timer(0, 5000)) + .pipe(debounceTime(1000)) + .subscribe(parts => { + let token = parts[0]; + let authMethod = parts[1]; + if (authMethod === 'Basic') { + token = Base64.decode(token); + } + checkAuth(token, authMethod); + }); + return () => sub.unsubscribe(); + }, [context, context.api, checkAuth]); + return (