From 97a92cb8dbc163049b72190e568880e6aa81f4df Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Wed, 23 Mar 2022 14:48:45 -0600 Subject: [PATCH] update login and register page to not display if already logged in --- webapp/src/pages/loginPage.tsx | 10 ++++++++-- webapp/src/pages/registerPage.tsx | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/webapp/src/pages/loginPage.tsx b/webapp/src/pages/loginPage.tsx index 7f5513d8d..afe967b70 100644 --- a/webapp/src/pages/loginPage.tsx +++ b/webapp/src/pages/loginPage.tsx @@ -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(getLoggedIn) const handleLogin = async (): Promise => { const logged = await client.login(username, password) @@ -28,6 +29,11 @@ const LoginPage = () => { } } + if (loggedIn) { + history.replace('/') + return null + } + return (
{ const [errorMessage, setErrorMessage] = useState('') const history = useHistory() const dispatch = useAppDispatch() + const loggedIn = useAppSelector(getLoggedIn) const handleRegister = async (): Promise => { const queryString = new URLSearchParams(window.location.search) @@ -37,6 +38,11 @@ const RegisterPage = () => { } } + if (loggedIn) { + history.replace('/') + return null + } + return (