Skip to content

Commit

Permalink
feat(login): auto-retry login with existing credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Aug 27, 2021
1 parent 1dd627e commit 7fb7c48
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/app/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
<PageSection>
<Card>
Expand Down

0 comments on commit 7fb7c48

Please sign in to comment.