From a8f52e77b8813273cccb27bc32af36f3fafe7825 Mon Sep 17 00:00:00 2001 From: Arno V Date: Tue, 9 Jul 2024 11:07:13 -0400 Subject: [PATCH] fix: on failed login, isLading is never reset (#89) --- examples/code-flow/src/main.tsx | 3 +++ .../src/components/AuthProvider/AuthProvider.tsx | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/examples/code-flow/src/main.tsx b/examples/code-flow/src/main.tsx index 1b1e938..7e2fe08 100644 --- a/examples/code-flow/src/main.tsx +++ b/examples/code-flow/src/main.tsx @@ -9,6 +9,8 @@ export const App = ({ timeout }: { timeout: string }) => { useAuth(); const [apiResponse, setApiResponse] = useState({ data: "" }); + console.info({ isAuthenticated, isLoading }); + const logger = console; logger.log("isAuthenticated", isAuthenticated); logger.log("isLoading", isLoading); @@ -32,6 +34,7 @@ export const App = ({ timeout }: { timeout: string }) => { const response = await login( process.env.PUBLIC_TEST_USER as string, "invalid-password", + AUTH_TYPES.CODE, ); if (!response) { console.error(`==> [${Date.now()}] : `, "Login failed"); diff --git a/packages/auth-provider/src/components/AuthProvider/AuthProvider.tsx b/packages/auth-provider/src/components/AuthProvider/AuthProvider.tsx index e248db2..d55d230 100644 --- a/packages/auth-provider/src/components/AuthProvider/AuthProvider.tsx +++ b/packages/auth-provider/src/components/AuthProvider/AuthProvider.tsx @@ -190,6 +190,10 @@ export const AuthProvider = ({ return true; } removeStateAndLocalStorage(LOGIN_ERROR); + setAuthState((prev) => ({ + ...prev, + isLoading: false, + })); return false; } return false; @@ -219,6 +223,10 @@ export const AuthProvider = ({ return true; } removeStateAndLocalStorage(LOGIN_ERROR); + setAuthState((prev) => ({ + ...prev, + isLoading: false, + })); return false; };