1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-12 09:04:14 +02:00

update login and register page to not display if already logged in

This commit is contained in:
Scott Bishel 2022-03-23 14:48:45 -06:00
parent aa540e73ce
commit 97a92cb8db
2 changed files with 16 additions and 4 deletions

View File

@ -4,8 +4,8 @@ import React, {useState} from 'react'
import {useHistory, Link} from 'react-router-dom' import {useHistory, Link} 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 +17,7 @@ const LoginPage = () => {
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 handleLogin = async (): Promise<void> => { const handleLogin = async (): Promise<void> => {
const logged = await client.login(username, password) const logged = await client.login(username, password)
@ -28,6 +29,11 @@ const LoginPage = () => {
} }
} }
if (loggedIn) {
history.replace('/')
return null
}
return ( return (
<div className='LoginPage'> <div className='LoginPage'>
<form <form

View File

@ -4,8 +4,8 @@ import React, {useState} from 'react'
import {useHistory, Link} from 'react-router-dom' import {useHistory, Link} 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,11 @@ const RegisterPage = () => {
} }
} }
if (loggedIn) {
history.replace('/')
return null
}
return ( return (
<div className='RegisterPage'> <div className='RegisterPage'>
<form <form