diff --git a/src/pages/Authorize/index.tsx b/src/pages/Authorize/index.tsx index bf1d81f..d7ebd32 100644 --- a/src/pages/Authorize/index.tsx +++ b/src/pages/Authorize/index.tsx @@ -50,7 +50,7 @@ const Authorize = () => { const { t } = useTranslation(); useEffect(() => { - if (!clientData) return; + if (!clientData || !scopesNotConsented) return; if (scopesNotConsented.length > 0) { setScopesConsented( clientData.recentConsent @@ -64,7 +64,7 @@ const Authorize = () => { return {error}; } - if (!clientData) return null; + if (!clientData || !scopesNotConsented) return null; if (scopesNotConsented.length > 0) { return ( diff --git a/src/pages/Authorize/useAuthorize.ts b/src/pages/Authorize/useAuthorize.ts index 289cdd3..f634b77 100644 --- a/src/pages/Authorize/useAuthorize.ts +++ b/src/pages/Authorize/useAuthorize.ts @@ -52,11 +52,11 @@ const useAuthorize = () => { const { user, logout } = useAuth(); const navigate = useNavigate(); const [error, setError] = useState(); - const [scopesConsented, setScopesConsented] = useState([]); - const [scopesNotConsented, setScopesNotConsented] = useState([]); + const [scopesConsented, setScopesConsented] = useState(); + const [scopesNotConsented, setScopesNotConsented] = useState(); const consent = (scopes: Scopes) => { - setScopesConsented((prev) => [...prev, ...scopes]); + setScopesConsented((prev) => [...(prev ?? []), ...scopes]); setScopesNotConsented([]); }; @@ -75,14 +75,20 @@ const useAuthorize = () => { if ( data.prompt !== "consent" && data.prompt !== "login" && - scopesConsented.length === 0 && + !scopesConsented && clientData.recentConsent.length ) { setScopesConsented(clientData.recentConsent); return; } - setScopesConsented(scopes.filter(isNotConsentRequiredScope)); - setScopesNotConsented(scopes.filter(isConsentRequiredScope)); + if (!scopesConsented) { + setScopesConsented(scopes.filter(isNotConsentRequiredScope)); + return; + } + if (!scopesNotConsented) { + setScopesNotConsented(scopes.filter(isConsentRequiredScope)); + return; + } if (scopesNotConsented.length !== 0) return; sessionStorage.removeItem(recentlyLoginKey);