mirror of
https://github.com/logto-io/logto.git
synced 2025-01-13 21:30:30 -05:00
refactor(console): set current tenant validated to false when resetting
This commit is contained in:
parent
d7f96a6559
commit
3cbfd7e712
6 changed files with 18 additions and 12 deletions
|
@ -29,7 +29,7 @@ import initI18n from './i18n/init';
|
||||||
void initI18n();
|
void initI18n();
|
||||||
|
|
||||||
function Content() {
|
function Content() {
|
||||||
const { tenants, currentTenantId } = useContext(TenantsContext);
|
const { tenants, currentTenantId, currentTenantValidated } = useContext(TenantsContext);
|
||||||
|
|
||||||
const resources = useMemo(
|
const resources = useMemo(
|
||||||
() =>
|
() =>
|
||||||
|
@ -78,9 +78,9 @@ function Content() {
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
{/**
|
{/**
|
||||||
* If it's not Cloud (OSS), render the tenant app container directly since only default tenant is available;
|
* If it's not Cloud (OSS), render the tenant app container directly since only default tenant is available;
|
||||||
* if it's Cloud, render the tenant app container only when init is complete and a tenant ID is available (in a tenant context).
|
* if it's Cloud, render the tenant app container only when a tenant ID is available (in a tenant context).
|
||||||
*/}
|
*/}
|
||||||
{!isCloud || currentTenantId ? (
|
{!isCloud || (currentTenantId && currentTenantValidated) ? (
|
||||||
<AppEndpointsProvider>
|
<AppEndpointsProvider>
|
||||||
<AppConfirmModalProvider>
|
<AppConfirmModalProvider>
|
||||||
<TenantAppContainer />
|
<TenantAppContainer />
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
|
|
||||||
import { TenantsContext } from '@/contexts/TenantsProvider';
|
import { TenantsContext } from '@/contexts/TenantsProvider';
|
||||||
|
import useValidateTenantAccess from '@/hooks/use-validate-tenant-access';
|
||||||
import useUserOnboardingData from '@/onboarding/hooks/use-user-onboarding-data';
|
import useUserOnboardingData from '@/onboarding/hooks/use-user-onboarding-data';
|
||||||
|
|
||||||
import AutoCreateTenant from './AutoCreateTenant';
|
import AutoCreateTenant from './AutoCreateTenant';
|
||||||
|
@ -11,6 +12,8 @@ export default function Main() {
|
||||||
const { tenants } = useContext(TenantsContext);
|
const { tenants } = useContext(TenantsContext);
|
||||||
const { isOnboarding } = useUserOnboardingData();
|
const { isOnboarding } = useUserOnboardingData();
|
||||||
|
|
||||||
|
useValidateTenantAccess();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If current tenant ID is not set, but there is at least one tenant available,
|
* If current tenant ID is not set, but there is at least one tenant available,
|
||||||
* trigger a redirect to the first tenant.
|
* trigger a redirect to the first tenant.
|
||||||
|
|
|
@ -11,7 +11,6 @@ import { isCloud } from '@/consts/env';
|
||||||
import useConfigs from '@/hooks/use-configs';
|
import useConfigs from '@/hooks/use-configs';
|
||||||
import useScroll from '@/hooks/use-scroll';
|
import useScroll from '@/hooks/use-scroll';
|
||||||
import useUserPreferences from '@/hooks/use-user-preferences';
|
import useUserPreferences from '@/hooks/use-user-preferences';
|
||||||
import useValidateTenantAccess from '@/hooks/use-validate-tenant-access';
|
|
||||||
import Broadcast from '@/onboarding/components/Broadcast';
|
import Broadcast from '@/onboarding/components/Broadcast';
|
||||||
|
|
||||||
import { getPath } from '../ConsoleContent/Sidebar';
|
import { getPath } from '../ConsoleContent/Sidebar';
|
||||||
|
@ -35,8 +34,6 @@ function AppContent() {
|
||||||
const { scrollTop } = useScroll(scrollableContent.current);
|
const { scrollTop } = useScroll(scrollableContent.current);
|
||||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
|
|
||||||
useValidateTenantAccess();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Navigate to the first menu item after configs are loaded.
|
// Navigate to the first menu item after configs are loaded.
|
||||||
if (!isLoading && location.pathname === '/') {
|
if (!isLoading && location.pathname === '/') {
|
||||||
|
|
|
@ -98,6 +98,7 @@ function TenantsProvider({ children }: Props) {
|
||||||
tenants,
|
tenants,
|
||||||
resetTenants: (tenants: TenantInfo[]) => {
|
resetTenants: (tenants: TenantInfo[]) => {
|
||||||
setTenants(tenants);
|
setTenants(tenants);
|
||||||
|
setCurrentTenantValidated(false);
|
||||||
setIsInitComplete(true);
|
setIsInitComplete(true);
|
||||||
},
|
},
|
||||||
appendTenant: (tenant: TenantInfo) => {
|
appendTenant: (tenant: TenantInfo) => {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { TenantsContext } from '@/contexts/TenantsProvider';
|
||||||
|
|
||||||
const useValidateTenantAccess = () => {
|
const useValidateTenantAccess = () => {
|
||||||
const { getAccessToken, signIn, isAuthenticated } = useLogto();
|
const { getAccessToken, signIn, isAuthenticated } = useLogto();
|
||||||
const { currentTenant, currentTenantValidated, setCurrentTenantValidated } =
|
const { currentTenant, currentTenantId, currentTenantValidated, setCurrentTenantValidated } =
|
||||||
useContext(TenantsContext);
|
useContext(TenantsContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -21,12 +21,20 @@ const useValidateTenantAccess = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isAuthenticated && currentTenant && !currentTenantValidated) {
|
if (isAuthenticated && currentTenantId && !currentTenantValidated) {
|
||||||
setCurrentTenantValidated();
|
setCurrentTenantValidated();
|
||||||
|
if (currentTenant) {
|
||||||
void validate(currentTenant);
|
void validate(currentTenant);
|
||||||
|
} else {
|
||||||
|
// The current tenant is unavailable to the user, maybe a deleted tenant or a tenant that
|
||||||
|
// the user has no access to. Fall back to the home page.
|
||||||
|
// eslint-disable-next-line @silverhand/fp/no-mutation
|
||||||
|
window.location.href = '/';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
currentTenant,
|
currentTenant,
|
||||||
|
currentTenantId,
|
||||||
currentTenantValidated,
|
currentTenantValidated,
|
||||||
getAccessToken,
|
getAccessToken,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
|
|
|
@ -11,7 +11,6 @@ import ProtectedRoutes from '@/containers/ProtectedRoutes';
|
||||||
import { AppThemeContext } from '@/contexts/AppThemeProvider';
|
import { AppThemeContext } from '@/contexts/AppThemeProvider';
|
||||||
import Toast from '@/ds-components/Toast';
|
import Toast from '@/ds-components/Toast';
|
||||||
import useSwrOptions from '@/hooks/use-swr-options';
|
import useSwrOptions from '@/hooks/use-swr-options';
|
||||||
import useValidateTenantAccess from '@/hooks/use-validate-tenant-access';
|
|
||||||
import NotFound from '@/pages/NotFound';
|
import NotFound from '@/pages/NotFound';
|
||||||
|
|
||||||
import { gtagAwTrackingId, gtagSignUpConversionId, logtoProductionHostname } from './constants';
|
import { gtagAwTrackingId, gtagSignUpConversionId, logtoProductionHostname } from './constants';
|
||||||
|
@ -66,8 +65,6 @@ function Layout() {
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useValidateTenantAccess();
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: { questionnaire },
|
data: { questionnaire },
|
||||||
} = useUserOnboardingData();
|
} = useUserOnboardingData();
|
||||||
|
|
Loading…
Add table
Reference in a new issue