0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00
logto/packages/console/src/App.tsx

77 lines
2.3 KiB
TypeScript
Raw Normal View History

import { UserScope } from '@logto/core-kit';
2022-05-17 21:37:30 +08:00
import { LogtoProvider } from '@logto/react';
import { adminConsoleApplicationId, PredefinedScope } from '@logto/schemas';
import { deduplicate } from '@silverhand/essentials';
2023-02-10 13:06:52 +08:00
import { useContext } from 'react';
import 'overlayscrollbars/styles/overlayscrollbars.css';
2022-02-28 10:35:14 +08:00
import './scss/normalized.scss';
import './scss/overlayscrollbars.scss';
// eslint-disable-next-line import/no-unassigned-import
import '@fontsource/roboto-mono';
2023-03-01 23:46:30 +08:00
import CloudApp from '@/cloud/App';
import { cloudApi, getManagementApi, meApi } from '@/consts/resources';
import initI18n from '@/i18n/init';
2023-03-01 23:46:30 +08:00
import { adminTenantEndpoint } from './consts';
import { isCloud } from './consts/cloud';
import AppConfirmModalProvider from './contexts/AppConfirmModalProvider';
import AppEndpointsProvider from './contexts/AppEndpointsProvider';
import TenantsProvider, { TenantsContext } from './contexts/TenantsProvider';
import Main from './pages/Main';
2022-02-28 22:18:01 +08:00
void initI18n();
const Content = () => {
2023-03-01 23:46:30 +08:00
const { tenants, isSettle, currentTenantId } = useContext(TenantsContext);
2023-02-10 13:06:52 +08:00
const resources = deduplicate([
2023-03-01 23:46:30 +08:00
// Explicitly add `currentTenantId` and deduplicate since the user may directly
// access a URL with Tenant ID, adding the ID from the URL here can possibly remove one
// additional redirect.
...(currentTenantId && [getManagementApi(currentTenantId).indicator]),
...(tenants ?? []).map(({ id }) => getManagementApi(id).indicator),
...(isCloud ? [cloudApi.indicator] : []),
meApi.indicator,
]);
const scopes = [
UserScope.Email,
UserScope.Identities,
UserScope.CustomData,
PredefinedScope.All,
cloudApi.scopes.CreateTenant, // It's fine to keep scope here since core will filter
];
2022-02-28 10:35:14 +08:00
return (
<LogtoProvider
config={{
endpoint: adminTenantEndpoint,
appId: adminConsoleApplicationId,
resources,
scopes,
}}
>
{!isCloud || isSettle ? (
<AppEndpointsProvider>
<AppConfirmModalProvider>
<Main />
</AppConfirmModalProvider>
</AppEndpointsProvider>
) : (
<CloudApp />
)}
</LogtoProvider>
2022-02-28 10:35:14 +08:00
);
};
const App = () => {
return (
<TenantsProvider>
<Content />
</TenantsProvider>
);
};
export default App;