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

73 lines
2 KiB
TypeScript
Raw Normal View History

import { UserScope } from '@logto/core-kit';
2022-05-17 08:37:30 -05:00
import { LogtoProvider } from '@logto/react';
import { adminConsoleApplicationId, PredefinedScope } from '@logto/schemas';
import { deduplicate } from '@silverhand/essentials';
2023-02-10 00:06:52 -05:00
import { useContext } from 'react';
import 'overlayscrollbars/styles/overlayscrollbars.css';
2022-02-27 21:35:14 -05:00
import './scss/normalized.scss';
import './scss/overlayscrollbars.scss';
// eslint-disable-next-line import/no-unassigned-import
import '@fontsource/roboto-mono';
import CloudApp from '@/cloud/App';
import { cloudApi, getManagementApi, meApi } from '@/consts/resources';
import initI18n from '@/i18n/init';
import { adminTenantEndpoint, getUserTenantId } from './consts';
import { isCloud } from './consts/cloud';
import AppEndpointsProvider from './contexts/AppEndpointsProvider';
import TenantsProvider, { TenantsContext } from './contexts/TenantsProvider';
import Main from './pages/Main';
2022-02-28 09:18:01 -05:00
void initI18n();
const Content = () => {
const {
tenants: { data, isSettle },
} = useContext(TenantsContext);
const currentTenantId = getUserTenantId();
2023-02-10 00:06:52 -05:00
const resources = deduplicate([
...(currentTenantId && [getManagementApi(currentTenantId).indicator]),
...(data ?? []).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-27 21:35:14 -05:00
return (
<LogtoProvider
config={{
endpoint: adminTenantEndpoint,
appId: adminConsoleApplicationId,
resources,
scopes,
}}
>
{!isCloud || (data && isSettle && currentTenantId) ? (
<AppEndpointsProvider>
<Main />
</AppEndpointsProvider>
) : (
<CloudApp />
)}
</LogtoProvider>
2022-02-27 21:35:14 -05:00
);
};
const App = () => {
return (
<TenantsProvider>
<Content />
</TenantsProvider>
);
};
export default App;