diff --git a/ui/src/Signin.tsx b/ui/src/Signin.tsx index 3fde313ea5..91558ce562 100644 --- a/ui/src/Signin.tsx +++ b/ui/src/Signin.tsx @@ -9,9 +9,6 @@ import {trySources} from 'src/onboarding/apis' import {ErrorHandling} from 'src/shared/decorators/errors' import {getMe} from 'src/shared/apis/v2/user' -// Utils -import {AuthContext} from 'src/utils/auth' - // Types import {RemoteDataState} from 'src/types' @@ -44,21 +41,23 @@ export class Signin extends PureComponent { const isSourcesAllowed = await trySources() const isUserSignedIn = isSourcesAllowed this.setState({loading: RemoteDataState.Done, isUserSignedIn}) + this.checkForLogin() + this.intervalID = setInterval(this.checkForLogin, FETCH_WAIT) if (!isUserSignedIn) { this.props.router.push('/signin') } } + public componentWillUnmount() { + clearInterval(this.intervalID) + } + public render() { if (this.isLoading) { return
} - return ( - - {this.props.children && React.cloneElement(this.props.children)} - - ) + return this.props.children && React.cloneElement(this.props.children) } private get isLoading(): boolean { @@ -69,12 +68,6 @@ export class Signin extends PureComponent { ) } - private handleSignInUser = () => { - this.intervalID = setInterval(this.checkForLogin, FETCH_WAIT) - this.setState({isUserSignedIn: true}) - this.props.router.push('/dashboards') - } - private checkForLogin = async () => { try { await getMe() diff --git a/ui/src/index.tsx b/ui/src/index.tsx index 5a9d9c3085..7a09882d4e 100644 --- a/ui/src/index.tsx +++ b/ui/src/index.tsx @@ -89,8 +89,8 @@ class Root extends PureComponent { path="/onboarding/:stepID/:substepID" component={OnboardingWizardPage} /> + - diff --git a/ui/src/onboarding/components/SigninForm.tsx b/ui/src/onboarding/components/SigninForm.tsx index 0fa90d8e4e..ac1a6223b1 100644 --- a/ui/src/onboarding/components/SigninForm.tsx +++ b/ui/src/onboarding/components/SigninForm.tsx @@ -1,5 +1,6 @@ // Libraries import React, {PureComponent, ChangeEvent} from 'react' +import {withRouter, WithRouterProps} from 'react-router' import {connect} from 'react-redux' import _, {get} from 'lodash' @@ -31,10 +32,9 @@ import * as copy from 'src/shared/copy/notifications' import {Links} from 'src/types/v2/links' import {Notification, NotificationFunc} from 'src/types' -export interface Props { +export interface OwnProps { links: Links notify: (message: Notification | NotificationFunc) => void - onSignInUser: () => void } interface State { @@ -42,6 +42,8 @@ interface State { password: string } +type Props = OwnProps & WithRouterProps + @ErrorHandling class SigninForm extends PureComponent { public state: State = { @@ -101,11 +103,12 @@ class SigninForm extends PureComponent { } private handleSignIn = async (): Promise => { - const {notify, onSignInUser} = this.props + const {notify, router} = this.props const {username, password} = this.state + try { await signin({username, password}) - onSignInUser() + router.push('/dashboards') } catch (error) { const message = get(error, 'data.msg', '') @@ -129,4 +132,4 @@ const mdtp = { export default connect( mstp, mdtp -)(SigninForm) +)(withRouter(SigninForm)) diff --git a/ui/src/onboarding/containers/SigninPage.tsx b/ui/src/onboarding/containers/SigninPage.tsx index f6a57fb703..e2c57fb1fb 100644 --- a/ui/src/onboarding/containers/SigninPage.tsx +++ b/ui/src/onboarding/containers/SigninPage.tsx @@ -7,24 +7,17 @@ import {ErrorHandling} from 'src/shared/decorators/errors' import SplashPage from 'src/shared/components/splash_page/SplashPage' import SigninForm from 'src/onboarding/components/SigninForm' -// Utils -import {AuthContext} from 'src/utils/auth' - @ErrorHandling class SigninPage extends PureComponent<{}> { public render() { return ( - - {({onSignInUser}) => ( - - - - - - - - )} - + + + + + + + ) } } diff --git a/ui/src/utils/auth.tsx b/ui/src/utils/auth.tsx deleted file mode 100644 index 0364c43d6c..0000000000 --- a/ui/src/utils/auth.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react' - -export interface SigninProps { - onSignInUser: () => void -} - -export const AuthContext = React.createContext(null)