Merge pull request #11053 from influxdata/fixes/sign-in-direct
Properly handle sign in page when there are no sourcespull/11067/head
commit
9ecb65d658
|
@ -2,9 +2,6 @@
|
|||
import React, {ReactElement, PureComponent} from 'react'
|
||||
import {withRouter, WithRouterProps} from 'react-router'
|
||||
|
||||
// APIs
|
||||
import {trySources} from 'src/onboarding/apis'
|
||||
|
||||
// Components
|
||||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||
import {getMe} from 'src/shared/apis/v2/user'
|
||||
|
@ -14,7 +11,6 @@ import {RemoteDataState} from 'src/types'
|
|||
|
||||
interface State {
|
||||
loading: RemoteDataState
|
||||
isUserSignedIn: boolean
|
||||
}
|
||||
|
||||
interface OwnProps {
|
||||
|
@ -33,19 +29,13 @@ export class Signin extends PureComponent<Props, State> {
|
|||
|
||||
this.state = {
|
||||
loading: RemoteDataState.NotStarted,
|
||||
isUserSignedIn: false,
|
||||
}
|
||||
}
|
||||
|
||||
public async componentDidMount() {
|
||||
const isSourcesAllowed = await trySources()
|
||||
const isUserSignedIn = isSourcesAllowed
|
||||
this.setState({loading: RemoteDataState.Done, isUserSignedIn})
|
||||
this.setState({loading: RemoteDataState.Done})
|
||||
this.checkForLogin()
|
||||
this.intervalID = setInterval(this.checkForLogin, FETCH_WAIT)
|
||||
if (!isUserSignedIn) {
|
||||
this.props.router.push('/signin')
|
||||
}
|
||||
}
|
||||
|
||||
public componentWillUnmount() {
|
||||
|
@ -73,7 +63,6 @@ export class Signin extends PureComponent<Props, State> {
|
|||
await getMe()
|
||||
} catch (error) {
|
||||
clearInterval(this.intervalID)
|
||||
this.setState({isUserSignedIn: false})
|
||||
this.props.router.push('/signin')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,19 @@ window.addEventListener('keyup', event => {
|
|||
}
|
||||
})
|
||||
|
||||
const MainLine = ({children}) => {
|
||||
const {pathname} = window.location
|
||||
if (
|
||||
pathname.includes('signin') ||
|
||||
pathname.includes('onboarding') ||
|
||||
pathname.includes('logout')
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
class Root extends PureComponent {
|
||||
public render() {
|
||||
return (
|
||||
|
@ -91,6 +104,7 @@ class Root extends PureComponent {
|
|||
component={OnboardingWizardPage}
|
||||
/>
|
||||
<Route path="/signin" component={SigninPage} />
|
||||
<Route component={MainLine}>
|
||||
<Route component={Signin}>
|
||||
<Route component={GetMe}>
|
||||
<Route component={GetOrganizations}>
|
||||
|
@ -134,6 +148,7 @@ class Root extends PureComponent {
|
|||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="/logout" component={Logout} />
|
||||
</Route>
|
||||
</Route>
|
||||
|
|
|
@ -1,16 +1,44 @@
|
|||
// Libraries
|
||||
import React, {PureComponent} from 'react'
|
||||
import {withRouter, WithRouterProps} from 'react-router'
|
||||
import _ from 'lodash'
|
||||
|
||||
// apis
|
||||
import {getSetupStatus} from 'src/onboarding/apis'
|
||||
|
||||
// Components
|
||||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||
import SplashPage from 'src/shared/components/splash_page/SplashPage'
|
||||
import SigninForm from 'src/onboarding/components/SigninForm'
|
||||
import {Spinner} from 'src/clockface'
|
||||
import {RemoteDataState} from 'src/types'
|
||||
|
||||
interface State {
|
||||
status: RemoteDataState
|
||||
}
|
||||
|
||||
@ErrorHandling
|
||||
class SigninPage extends PureComponent<{}> {
|
||||
class SigninPage extends PureComponent<WithRouterProps, State> {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
status: RemoteDataState.Loading,
|
||||
}
|
||||
}
|
||||
public async componentDidMount() {
|
||||
const isSetupAllowed = await getSetupStatus()
|
||||
|
||||
if (isSetupAllowed) {
|
||||
this.props.router.push('/onboarding/0')
|
||||
}
|
||||
|
||||
this.setState({status: RemoteDataState.Done})
|
||||
}
|
||||
|
||||
public render() {
|
||||
return (
|
||||
<Spinner loading={this.state.status}>
|
||||
<SplashPage panelWidthPixels={300}>
|
||||
<SplashPage.Panel>
|
||||
<SplashPage.Logo />
|
||||
|
@ -18,8 +46,9 @@ class SigninPage extends PureComponent<{}> {
|
|||
<SigninForm />
|
||||
</SplashPage.Panel>
|
||||
</SplashPage>
|
||||
</Spinner>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default SigninPage
|
||||
export default withRouter(SigninPage)
|
||||
|
|
Loading…
Reference in New Issue