feat(ui): login redirect to /me (#11166)
parent
eef66bd7ab
commit
6e0635861e
|
@ -22,7 +22,14 @@ export class Logout extends PureComponent<Props> {
|
|||
|
||||
private handleSignOut = async () => {
|
||||
await logout()
|
||||
this.props.router.push('/')
|
||||
const {query} = this.props.location
|
||||
let returnTo = ''
|
||||
|
||||
if (query && query.returnTo) {
|
||||
returnTo = `?returnTo=${query.returnTo}`
|
||||
}
|
||||
|
||||
this.props.router.push(`/signin${returnTo}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,8 +62,22 @@ export class Signin extends PureComponent<Props, State> {
|
|||
try {
|
||||
await getMe()
|
||||
} catch (error) {
|
||||
const {
|
||||
location: {pathname},
|
||||
} = this.props
|
||||
clearInterval(this.intervalID)
|
||||
this.props.router.push('/signin')
|
||||
|
||||
if (pathname.startsWith('/signin')) {
|
||||
return
|
||||
}
|
||||
|
||||
let returnTo = ''
|
||||
|
||||
if (pathname !== '/') {
|
||||
returnTo = `?returnTo=${pathname}`
|
||||
}
|
||||
|
||||
this.props.router.push(`/signin${returnTo}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
// Libraries
|
||||
import React, {SFC} from 'react'
|
||||
import {Link} from 'react-router'
|
||||
import {withRouter, WithRouterProps} from 'react-router'
|
||||
|
||||
// Components
|
||||
import {Button, ComponentSize} from 'src/clockface'
|
||||
|
||||
const LogoutButton: SFC = () => (
|
||||
<Link to={`/logout`}>
|
||||
const LogoutButton: SFC<WithRouterProps> = props => (
|
||||
<Link to={`/logout?returnTo=${props.location.pathname}`}>
|
||||
<Button text="Logout" size={ComponentSize.ExtraSmall} />
|
||||
</Link>
|
||||
)
|
||||
|
||||
export default LogoutButton
|
||||
export default withRouter<{}>(LogoutButton)
|
||||
|
|
|
@ -103,12 +103,12 @@ class SigninForm extends PureComponent<Props, State> {
|
|||
}
|
||||
|
||||
private handleSignIn = async (): Promise<void> => {
|
||||
const {notify, router} = this.props
|
||||
const {notify} = this.props
|
||||
const {username, password} = this.state
|
||||
|
||||
try {
|
||||
await signin({username, password})
|
||||
router.push('/dashboards')
|
||||
this.handleRedirect()
|
||||
} catch (error) {
|
||||
const message = get(error, 'data.msg', '')
|
||||
|
||||
|
@ -119,6 +119,17 @@ class SigninForm extends PureComponent<Props, State> {
|
|||
notify({...copy.SigninError, message})
|
||||
}
|
||||
}
|
||||
|
||||
private handleRedirect() {
|
||||
const {router} = this.props
|
||||
const {query} = this.props.location
|
||||
|
||||
if (query && query.returnTo) {
|
||||
router.push(query.returnTo)
|
||||
} else {
|
||||
router.push('/me')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mstp = ({links}) => ({
|
||||
|
|
|
@ -122,7 +122,7 @@ class OnboardingWizard extends PureComponent<Props> {
|
|||
private handleExit = () => {
|
||||
const {router, onCompleteSetup} = this.props
|
||||
onCompleteSetup()
|
||||
router.push(`/`)
|
||||
router.push(`/me`)
|
||||
}
|
||||
|
||||
private get onboardingStepProps(): OnboardingStepProps {
|
||||
|
|
|
@ -12,6 +12,7 @@ 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'
|
||||
import Notifications from 'src/shared/components/notifications/Notifications'
|
||||
|
||||
interface State {
|
||||
status: RemoteDataState
|
||||
|
@ -39,6 +40,7 @@ class SigninPage extends PureComponent<WithRouterProps, State> {
|
|||
public render() {
|
||||
return (
|
||||
<Spinner loading={this.state.status}>
|
||||
<Notifications inPresentationMode={true} />
|
||||
<SplashPage panelWidthPixels={300}>
|
||||
<SplashPage.Panel>
|
||||
<SplashPage.Logo />
|
||||
|
|
|
@ -32,7 +32,7 @@ class SideNav extends PureComponent<Props> {
|
|||
|
||||
public render() {
|
||||
const {isHidden, me} = this.props
|
||||
|
||||
const {location} = this.props
|
||||
if (isHidden) {
|
||||
return null
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class SideNav extends PureComponent<Props> {
|
|||
>
|
||||
<NavMenu.SubItem
|
||||
title="Logout"
|
||||
link="/logout"
|
||||
link={`/logout?returnTo=${location.pathname}`}
|
||||
location={location.pathname}
|
||||
highlightWhen={[]}
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue