From 9eeb00e801da33d9d4be94ba16f67af26645e1df Mon Sep 17 00:00:00 2001 From: Raul Kele Date: Thu, 12 Jan 2023 12:41:44 +0200 Subject: [PATCH] fix: fixed external navigation bug Signed-off-by: Raul Kele --- public/index.html | 1 + src/App.js | 15 +++------------ src/components/SignIn.jsx | 26 +++++++++----------------- src/pages/LoginPage.jsx | 10 ++-------- 4 files changed, 15 insertions(+), 37 deletions(-) diff --git a/public/index.html b/public/index.html index 9011ab21..4e2b0605 100644 --- a/public/index.html +++ b/public/index.html @@ -2,6 +2,7 @@ + diff --git a/src/App.js b/src/App.js index a5a89d48..3b26dd24 100644 --- a/src/App.js +++ b/src/App.js @@ -16,7 +16,6 @@ function App() { return localStorageToken ? true : false; }; - const [isAuthEnabled, setIsAuthEnabled] = useState(true); const [isLoggedIn, setIsLoggedIn] = useState(isToken()); return ( @@ -29,21 +28,13 @@ function App() { } /> } /> } /> + } /> }> - - } - /> + } /> } /> + } /> diff --git a/src/components/SignIn.jsx b/src/components/SignIn.jsx index 4363567f..cd6e2ec7 100644 --- a/src/components/SignIn.jsx +++ b/src/components/SignIn.jsx @@ -99,13 +99,7 @@ const useStyles = makeStyles(() => ({ } })); -export default function SignIn({ - isAuthEnabled, - setIsAuthEnabled, - isLoggedIn, - setIsLoggedIn, - wrapperSetLoading = () => {} -}) { +export default function SignIn({ isLoggedIn, setIsLoggedIn, wrapperSetLoading = () => {} }) { const [usernameError, setUsernameError] = useState(null); const [passwordError, setPasswordError] = useState(null); const [username, setUsername] = useState(null); @@ -119,7 +113,7 @@ export default function SignIn({ useEffect(() => { setIsLoading(true); - if (isAuthEnabled && isLoggedIn) { + if (isLoggedIn) { setIsLoading(false); wrapperSetLoading(false); navigate('/home'); @@ -128,7 +122,7 @@ export default function SignIn({ .get(`${host()}/v2/`, abortController.signal) .then((response) => { if (response.status === 200) { - setIsAuthEnabled(false); + localStorage.setItem('token', '-'); setIsLoggedIn(true); setIsLoading(false); wrapperSetLoading(false); @@ -136,7 +130,7 @@ export default function SignIn({ } }) .catch(() => { - setIsAuthEnabled(true); + localStorage.setItem('token', '-'); setIsLoading(false); wrapperSetLoading(false); }); @@ -150,7 +144,7 @@ export default function SignIn({ event.preventDefault(); setRequestProcessing(true); let cfg = {}; - if (isAuthEnabled) { + if (isLoggedIn) { const token = btoa(username + ':' + password); cfg = { headers: { @@ -162,12 +156,10 @@ export default function SignIn({ .get(`${host()}${endpoints.repoList}`, abortController.signal, cfg) .then((response) => { if (response.data && response.data.data) { - if (isAuthEnabled) { - const token = btoa(username + ':' + password); - localStorage.setItem('token', token); - setRequestProcessing(false); - setRequestError(false); - } + const token = btoa(username + ':' + password); + localStorage.setItem('token', token); + setRequestProcessing(false); + setRequestError(false); setIsLoggedIn(true); navigate('/home'); } diff --git a/src/pages/LoginPage.jsx b/src/pages/LoginPage.jsx index 45e6b046..fdf6d8fd 100644 --- a/src/pages/LoginPage.jsx +++ b/src/pages/LoginPage.jsx @@ -20,7 +20,7 @@ const useStyles = makeStyles(() => ({ } })); -function LoginPage({ isAuthEnabled, setIsAuthEnabled, isLoggedIn, setIsLoggedIn }) { +function LoginPage({ isLoggedIn, setIsLoggedIn }) { const [isLoading, setIsLoading] = useState(true); const classes = useStyles(); @@ -31,13 +31,7 @@ function LoginPage({ isAuthEnabled, setIsAuthEnabled, isLoggedIn, setIsLoggedIn - + );