update login and register page to not display if already logged in
This commit is contained in:
parent
aa540e73ce
commit
97a92cb8db
2 changed files with 16 additions and 4 deletions
|
@ -4,8 +4,8 @@ import React, {useState} from 'react'
|
|||
import {useHistory, Link} from 'react-router-dom'
|
||||
import {FormattedMessage} from 'react-intl'
|
||||
|
||||
import {useAppDispatch} from '../store/hooks'
|
||||
import {fetchMe} from '../store/users'
|
||||
import {useAppDispatch, useAppSelector} from '../store/hooks'
|
||||
import {fetchMe, getLoggedIn} from '../store/users'
|
||||
|
||||
import Button from '../widgets/buttons/button'
|
||||
import client from '../octoClient'
|
||||
|
@ -17,6 +17,7 @@ const LoginPage = () => {
|
|||
const [errorMessage, setErrorMessage] = useState('')
|
||||
const history = useHistory()
|
||||
const dispatch = useAppDispatch()
|
||||
const loggedIn = useAppSelector<boolean|null>(getLoggedIn)
|
||||
|
||||
const handleLogin = async (): Promise<void> => {
|
||||
const logged = await client.login(username, password)
|
||||
|
@ -28,6 +29,11 @@ const LoginPage = () => {
|
|||
}
|
||||
}
|
||||
|
||||
if (loggedIn) {
|
||||
history.replace('/')
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='LoginPage'>
|
||||
<form
|
||||
|
|
|
@ -4,8 +4,8 @@ import React, {useState} from 'react'
|
|||
import {useHistory, Link} from 'react-router-dom'
|
||||
import {FormattedMessage} from 'react-intl'
|
||||
|
||||
import {useAppDispatch} from '../store/hooks'
|
||||
import {fetchMe} from '../store/users'
|
||||
import {useAppDispatch, useAppSelector} from '../store/hooks'
|
||||
import {fetchMe, getLoggedIn} from '../store/users'
|
||||
|
||||
import Button from '../widgets/buttons/button'
|
||||
import client from '../octoClient'
|
||||
|
@ -18,6 +18,7 @@ const RegisterPage = () => {
|
|||
const [errorMessage, setErrorMessage] = useState('')
|
||||
const history = useHistory()
|
||||
const dispatch = useAppDispatch()
|
||||
const loggedIn = useAppSelector<boolean|null>(getLoggedIn)
|
||||
|
||||
const handleRegister = async (): Promise<void> => {
|
||||
const queryString = new URLSearchParams(window.location.search)
|
||||
|
@ -37,6 +38,11 @@ const RegisterPage = () => {
|
|||
}
|
||||
}
|
||||
|
||||
if (loggedIn) {
|
||||
history.replace('/')
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='RegisterPage'>
|
||||
<form
|
||||
|
|
Loading…
Reference in a new issue