0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

fix(console): check scope only when data is ready (#6329)

This commit is contained in:
Gao Sun 2024-07-25 12:00:34 +08:00 committed by GitHub
parent 29e9bfce03
commit 89b8662a15
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,7 +22,7 @@ const useTenantScopeListener = () => {
const { clearAccessToken, clearAllTokens, getOrganizationTokenClaims, signIn } = useLogto();
const [tokenClaims, setTokenClaims] = useState<string[]>();
const redirectUri = useRedirectUri();
const { scopes = [], isLoading } = useCurrentTenantScopes();
const { scopes, isLoading } = useCurrentTenantScopes();
useEffect(() => {
(async () => {
@ -33,20 +33,20 @@ const useTenantScopeListener = () => {
}, [currentTenantId, getOrganizationTokenClaims]);
useEffect(() => {
if (isCloud && !isLoading && scopes.length === 0) {
if (isCloud && !isLoading && scopes?.length === 0) {
// User has no access to the current tenant. Navigate to root and it will return to the
// last visited tenant, or fallback to the page where the user can create a new tenant.
removeTenant(currentTenantId);
navigateTenant('');
}
}, [currentTenantId, isLoading, navigateTenant, removeTenant, scopes.length]);
}, [currentTenantId, isLoading, navigateTenant, removeTenant, scopes?.length]);
useEffect(() => {
if (!isCloud || isLoading || tokenClaims === undefined) {
return;
}
const hasScopesGranted = scopes.some((scope) => !tokenClaims.includes(scope));
const hasScopesRevoked = tokenClaims.some((claim) => !scopes.includes(claim));
const hasScopesGranted = scopes?.some((scope) => !tokenClaims.includes(scope));
const hasScopesRevoked = tokenClaims.some((claim) => !scopes?.includes(claim));
if (hasScopesGranted) {
(async () => {
// User has been newly granted scopes. Need to re-consent to obtain the additional scopes.