Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent double auth check #183

Open
mstone121 opened this issue Nov 7, 2022 · 2 comments
Open

Prevent double auth check #183

mstone121 opened this issue Nov 7, 2022 · 2 comments
Labels
bug Something isn't working Task 3.6 Front-end implementation

Comments

@mstone121
Copy link
Contributor

Overview

Inspection of the network tab reveals that the auth check happens twice when the app loads.

Expected Behavior

This check should happen only once.

Actual Behavior

It happens twice.

Steps to Reproduce

Demo

Screen Shot 2022-11-07 at 10 59 09 AM

@mstone121 mstone121 added the bug Something isn't working label Nov 7, 2022
@rajadain
Copy link
Contributor

rajadain commented Nov 7, 2022

This actually happens 5 times for me for successful logins:

image

Sometimes they return at different rates and result in the UI being logged in but the API requests not being authorized.

@rajadain rajadain added the Task 3.6 Front-end implementation label Nov 8, 2022
@jacobtylerwalls
Copy link
Contributor

Toyed with this during the Q&A at showcase today. This seems to work for me:

diff --git a/src/app/src/components/AuthenticationGuard.js b/src/app/src/components/AuthenticationGuard.js
index 20371a2..d97431f 100644
--- a/src/app/src/components/AuthenticationGuard.js
+++ b/src/app/src/components/AuthenticationGuard.js
@@ -11,7 +11,7 @@ export default function AuthenticationGuard({ children }) {
     const dispatch = useDispatch();
     const location = useLocation();
     const user = useSelector(state => state.auth.user);
-    const [authChecked, setAuthChecked] = useState(false);
+    const [authChecked, setAuthChecked] = useState(!!user);
 
     useEffect(() => {
         if (!authChecked) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task 3.6 Front-end implementation
Projects
None yet
Development

No branches or pull requests

3 participants