Merge pull request #2618 from mattermost/MM-40430-redirect-login
MM-40430 - Redirect user if already logged in
This commit is contained in:
commit
20f6b3e00b
5 changed files with 32 additions and 14 deletions
|
@ -56,10 +56,12 @@ describe('Login actions', () => {
|
||||||
cy.get('button').contains('Change password').click()
|
cy.get('button').contains('Change password').click()
|
||||||
cy.get('.succeeded').click()
|
cy.get('.succeeded').click()
|
||||||
workspaceIsAvailable()
|
workspaceIsAvailable()
|
||||||
|
logoutUser()
|
||||||
|
|
||||||
// Can log in user with new password
|
// Can log in user with new password
|
||||||
cy.log('**Can log in user with new password**')
|
cy.log('**Can log in user with new password**')
|
||||||
loginUser(newPassword).then(() => resetPassword(newPassword))
|
loginUser(newPassword).then(() => resetPassword(newPassword))
|
||||||
|
logoutUser()
|
||||||
|
|
||||||
// Can't register second user without invite link
|
// Can't register second user without invite link
|
||||||
cy.log('**Can\'t register second user without invite link**')
|
cy.log('**Can\'t register second user without invite link**')
|
||||||
|
@ -82,10 +84,7 @@ describe('Login actions', () => {
|
||||||
cy.get('.Button').contains('Copied').should('exist')
|
cy.get('.Button').contains('Copied').should('exist')
|
||||||
|
|
||||||
cy.get('a.shareUrl').invoke('attr', 'href').then((inviteLink) => {
|
cy.get('a.shareUrl').invoke('attr', 'href').then((inviteLink) => {
|
||||||
// Log out existing user
|
logoutUser()
|
||||||
cy.log('**Log out existing user**')
|
|
||||||
cy.get('.Sidebar .SidebarUserMenu').click()
|
|
||||||
cy.get('.menu-name').contains('Log out').click()
|
|
||||||
|
|
||||||
// Register a new user
|
// Register a new user
|
||||||
cy.log('**Register new user**')
|
cy.log('**Register new user**')
|
||||||
|
@ -112,6 +111,13 @@ describe('Login actions', () => {
|
||||||
return workspaceIsAvailable()
|
return workspaceIsAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const logoutUser = () => {
|
||||||
|
cy.log('**Log out existing user**')
|
||||||
|
cy.get('.SidebarUserMenu').click()
|
||||||
|
cy.get('.menu-name').contains('Log out').click()
|
||||||
|
cy.location('pathname').should('eq', '/login')
|
||||||
|
}
|
||||||
|
|
||||||
const resetPassword = (oldPassword: string) => {
|
const resetPassword = (oldPassword: string) => {
|
||||||
cy.apiGetMe().then((userId) => cy.apiChangePassword(userId, oldPassword, password))
|
cy.apiGetMe().then((userId) => cy.apiChangePassword(userId, oldPassword, password))
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ import {IUser} from '../../user'
|
||||||
import FocalboardLogoIcon from '../../widgets/icons/focalboard_logo'
|
import FocalboardLogoIcon from '../../widgets/icons/focalboard_logo'
|
||||||
import Menu from '../../widgets/menu'
|
import Menu from '../../widgets/menu'
|
||||||
import MenuWrapper from '../../widgets/menuWrapper'
|
import MenuWrapper from '../../widgets/menuWrapper'
|
||||||
import {getMe} from '../../store/users'
|
import {getMe, setMe} from '../../store/users'
|
||||||
import {useAppSelector} from '../../store/hooks'
|
import {useAppSelector, useAppDispatch} from '../../store/hooks'
|
||||||
import {Utils} from '../../utils'
|
import {Utils} from '../../utils'
|
||||||
|
|
||||||
import ModalWrapper from '../modalWrapper'
|
import ModalWrapper from '../modalWrapper'
|
||||||
|
@ -26,6 +26,7 @@ import './sidebarUserMenu.scss'
|
||||||
declare let window: IAppWindow
|
declare let window: IAppWindow
|
||||||
|
|
||||||
const SidebarUserMenu = () => {
|
const SidebarUserMenu = () => {
|
||||||
|
const dispatch = useAppDispatch()
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
const [showRegistrationLinkDialog, setShowRegistrationLinkDialog] = useState(false)
|
const [showRegistrationLinkDialog, setShowRegistrationLinkDialog] = useState(false)
|
||||||
const user = useAppSelector<IUser|null>(getMe)
|
const user = useAppSelector<IUser|null>(getMe)
|
||||||
|
@ -60,6 +61,7 @@ const SidebarUserMenu = () => {
|
||||||
name={intl.formatMessage({id: 'Sidebar.logout', defaultMessage: 'Log out'})}
|
name={intl.formatMessage({id: 'Sidebar.logout', defaultMessage: 'Log out'})}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await octoClient.logout()
|
await octoClient.logout()
|
||||||
|
dispatch(setMe(null))
|
||||||
history.push('/login')
|
history.push('/login')
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
import React, {useState} from 'react'
|
import React, {useState} from 'react'
|
||||||
|
import {Link, Redirect, useLocation, useHistory} from 'react-router-dom'
|
||||||
import {Link, useLocation, useHistory} from 'react-router-dom'
|
|
||||||
import {FormattedMessage} from 'react-intl'
|
import {FormattedMessage} from 'react-intl'
|
||||||
|
|
||||||
import {useAppDispatch} from '../store/hooks'
|
import {useAppDispatch, useAppSelector} from '../store/hooks'
|
||||||
import {fetchMe} from '../store/users'
|
import {fetchMe, getLoggedIn} from '../store/users'
|
||||||
|
|
||||||
import Button from '../widgets/buttons/button'
|
import Button from '../widgets/buttons/button'
|
||||||
import client from '../octoClient'
|
import client from '../octoClient'
|
||||||
|
@ -17,6 +16,7 @@ const LoginPage = () => {
|
||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
const [errorMessage, setErrorMessage] = useState('')
|
const [errorMessage, setErrorMessage] = useState('')
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
|
const loggedIn = useAppSelector<boolean|null>(getLoggedIn)
|
||||||
const queryParams = new URLSearchParams(useLocation().search)
|
const queryParams = new URLSearchParams(useLocation().search)
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
|
|
||||||
|
@ -34,6 +34,10 @@ const LoginPage = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (loggedIn) {
|
||||||
|
return <Redirect to={'/'}/>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='LoginPage'>
|
<div className='LoginPage'>
|
||||||
<form
|
<form
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
import React, {useState} from 'react'
|
import React, {useState} from 'react'
|
||||||
import {useHistory, Link} from 'react-router-dom'
|
import {useHistory, Link, Redirect} from 'react-router-dom'
|
||||||
import {FormattedMessage} from 'react-intl'
|
import {FormattedMessage} from 'react-intl'
|
||||||
|
|
||||||
import {useAppDispatch} from '../store/hooks'
|
import {useAppDispatch, useAppSelector} from '../store/hooks'
|
||||||
import {fetchMe} from '../store/users'
|
import {fetchMe, getLoggedIn} from '../store/users'
|
||||||
|
|
||||||
import Button from '../widgets/buttons/button'
|
import Button from '../widgets/buttons/button'
|
||||||
import client from '../octoClient'
|
import client from '../octoClient'
|
||||||
|
@ -18,6 +18,7 @@ const RegisterPage = () => {
|
||||||
const [errorMessage, setErrorMessage] = useState('')
|
const [errorMessage, setErrorMessage] = useState('')
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
|
const loggedIn = useAppSelector<boolean|null>(getLoggedIn)
|
||||||
|
|
||||||
const handleRegister = async (): Promise<void> => {
|
const handleRegister = async (): Promise<void> => {
|
||||||
const queryString = new URLSearchParams(window.location.search)
|
const queryString = new URLSearchParams(window.location.search)
|
||||||
|
@ -37,6 +38,10 @@ const RegisterPage = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (loggedIn) {
|
||||||
|
return <Redirect to={'/'}/>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='RegisterPage'>
|
<div className='RegisterPage'>
|
||||||
<form
|
<form
|
||||||
|
|
|
@ -44,8 +44,9 @@ const usersSlice = createSlice({
|
||||||
name: 'users',
|
name: 'users',
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
setMe: (state, action: PayloadAction<IUser>) => {
|
setMe: (state, action: PayloadAction<IUser|null>) => {
|
||||||
state.me = action.payload
|
state.me = action.payload
|
||||||
|
state.loggedIn = Boolean(state.me)
|
||||||
},
|
},
|
||||||
setBoardUsers: (state, action: PayloadAction<IUser[]>) => {
|
setBoardUsers: (state, action: PayloadAction<IUser[]>) => {
|
||||||
state.boardUsers = action.payload.reduce((acc: {[key: string]: IUser}, user: IUser) => {
|
state.boardUsers = action.payload.reduce((acc: {[key: string]: IUser}, user: IUser) => {
|
||||||
|
|
Loading…
Reference in a new issue