From de81f79c4a105a7797385c56626937ba0c8bf4cd Mon Sep 17 00:00:00 2001 From: spencerwooo Date: Mon, 20 Dec 2021 20:55:12 +0800 Subject: [PATCH] fix an issue where entering password triggers reload --- components/Auth.tsx | 6 ++++-- components/Navbar.tsx | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/components/Auth.tsx b/components/Auth.tsx index fcc4d53..7fab3c6 100644 --- a/components/Auth.tsx +++ b/components/Auth.tsx @@ -2,7 +2,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import Image from 'next/image' import { useRouter } from 'next/router' -import { FunctionComponent } from 'react' +import { FunctionComponent, useState } from 'react' import { matchProtectedRoute } from '../utils/protectedRouteHandler' import useLocalStorage from '../utils/useLocalStorage' @@ -11,7 +11,8 @@ const Auth: FunctionComponent<{ redirect: string }> = ({ redirect }) => { const authTokenPath = matchProtectedRoute(redirect) const router = useRouter() - const [token, setToken] = useLocalStorage(authTokenPath, '') + const [token, setToken] = useState('') + const [persistedToken, setPersistedToken] = useLocalStorage(authTokenPath, '') return (
@@ -37,6 +38,7 @@ const Auth: FunctionComponent<{ redirect: string }> = ({ redirect }) => { }} onKeyPress={e => { if (e.key === 'Enter' || e.key === 'NumpadEnter') { + setPersistedToken(token) router.reload() } }} diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 6e739da..bb80a3e 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -76,7 +76,7 @@ const Navbar = () => { className="hover:bg-gray-200 dark:text-white dark:hover:bg-gray-700 flex items-center p-2 space-x-2 rounded" onClick={() => setIsOpen(true)} > - Logout + Logout )} @@ -139,7 +139,7 @@ const Navbar = () => { Cancel