mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(console): userEndpoint -> tenantEndpoint (#4228)
This commit is contained in:
parent
b9a05c0034
commit
129d22980f
10 changed files with 35 additions and 35 deletions
|
@ -137,7 +137,7 @@ function Providers() {
|
|||
|
||||
/** Renders different routes based on the user's onboarding status. */
|
||||
function AppRoutes() {
|
||||
const { userEndpoint } = useContext(AppDataContext);
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
const { isLoaded } = useMeCustomData();
|
||||
const { isOnboarding } = useUserOnboardingData();
|
||||
const { isAuthenticated } = useLogto();
|
||||
|
@ -147,7 +147,7 @@ function AppRoutes() {
|
|||
// Authenticated user should load onboarding data before rendering the app.
|
||||
// This looks weird and it will be refactored soon by merging the onboarding
|
||||
// routes with the console routes.
|
||||
if (!userEndpoint || (isCloud && isAuthenticated && !isLoaded)) {
|
||||
if (!tenantEndpoint || (isCloud && isAuthenticated && !isLoaded)) {
|
||||
return <AppLoading />;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ function ConfigForm({ formItems, className, connectorId, connectorType }: Props)
|
|||
control,
|
||||
formState: { errors },
|
||||
} = useFormContext<ConnectorFormType>();
|
||||
const { userEndpoint } = useContext(AppDataContext);
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
const { data: customDomain } = useCustomDomain();
|
||||
const callbackUri = new URL(`/callback/${connectorId}`, userEndpoint).toString();
|
||||
const callbackUri = new URL(`/callback/${connectorId}`, tenantEndpoint).toString();
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
|
@ -51,13 +51,13 @@ function ConfigForm({ formItems, className, connectorId, connectorType }: Props)
|
|||
: callbackUri
|
||||
}
|
||||
/>
|
||||
{customDomain?.status === DomainStatus.Active && userEndpoint && (
|
||||
{customDomain?.status === DomainStatus.Active && tenantEndpoint && (
|
||||
<div className={styles.description}>
|
||||
<DynamicT
|
||||
forKey="domain.custom_social_callback_url_note"
|
||||
interpolation={{
|
||||
custom: customDomain.domain,
|
||||
default: new URL(userEndpoint).host,
|
||||
default: new URL(tenantEndpoint).host,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -20,7 +20,7 @@ type Props = {
|
|||
|
||||
function LivePreviewButton({ size, type, isDisabled }: Props) {
|
||||
const { configs, updateConfigs } = useConfigs();
|
||||
const { userEndpoint } = useContext(AppDataContext);
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||
|
||||
return (
|
||||
|
@ -43,7 +43,7 @@ function LivePreviewButton({ size, type, isDisabled }: Props) {
|
|||
void updateConfigs({ livePreviewChecked: true });
|
||||
}
|
||||
|
||||
window.open(new URL('/demo-app', userEndpoint), '_blank');
|
||||
window.open(new URL('/demo-app', tenantEndpoint), '_blank');
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
|
|
|
@ -29,7 +29,7 @@ function SignInExperiencePreview({ platform, mode, language = 'en', signInExperi
|
|||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||
|
||||
const { customPhrases } = useUiLanguages();
|
||||
const { userEndpoint } = useContext(AppDataContext);
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
const previewRef = useRef<HTMLIFrameElement>(null);
|
||||
const { data: allConnectors } = useSWR<ConnectorResponse[], RequestError>('api/connectors');
|
||||
const [iframeLoaded, setIframeLoaded] = useState(false);
|
||||
|
@ -76,9 +76,9 @@ function SignInExperiencePreview({ platform, mode, language = 'en', signInExperi
|
|||
|
||||
previewRef.current?.contentWindow?.postMessage(
|
||||
{ sender: 'ac_preview', config: configForUiPage },
|
||||
userEndpoint?.origin ?? ''
|
||||
tenantEndpoint?.origin ?? ''
|
||||
);
|
||||
}, [userEndpoint?.origin, configForUiPage, customPhrases]);
|
||||
}, [tenantEndpoint?.origin, configForUiPage, customPhrases]);
|
||||
|
||||
const iframeOnLoadEventHandler = useCallback(() => {
|
||||
setIframeLoaded(true);
|
||||
|
@ -102,7 +102,7 @@ function SignInExperiencePreview({ platform, mode, language = 'en', signInExperi
|
|||
postPreviewMessage();
|
||||
}, [iframeLoaded, postPreviewMessage]);
|
||||
|
||||
if (!userEndpoint) {
|
||||
if (!tenantEndpoint) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ function SignInExperiencePreview({ platform, mode, language = 'en', signInExperi
|
|||
ref={previewRef}
|
||||
// Allow all sandbox rules
|
||||
sandbox={undefined}
|
||||
src={new URL('/sign-in?preview=true', userEndpoint).toString()}
|
||||
src={new URL('/sign-in?preview=true', tenantEndpoint).toString()}
|
||||
tabIndex={-1}
|
||||
title={t('sign_in_exp.preview.title')}
|
||||
/>
|
||||
|
|
|
@ -17,7 +17,7 @@ type AppData = {
|
|||
*
|
||||
* Always use this value as the base URL when referring to the Logto URL of the current user's tenant.
|
||||
*/
|
||||
userEndpoint?: URL;
|
||||
tenantEndpoint?: URL;
|
||||
};
|
||||
|
||||
export const AppDataContext = createContext<AppData>({});
|
||||
|
@ -26,7 +26,7 @@ export const AppDataContext = createContext<AppData>({});
|
|||
function AppDataProvider({ children }: Props) {
|
||||
const { currentTenantId } = useContext(TenantsContext);
|
||||
|
||||
const { data: userEndpoint } = useSWRImmutable(
|
||||
const { data: tenantEndpoint } = useSWRImmutable(
|
||||
`api/.well-known/endpoints/${currentTenantId}`,
|
||||
async (pathname) => {
|
||||
const { user } = await ky
|
||||
|
@ -39,9 +39,9 @@ function AppDataProvider({ children }: Props) {
|
|||
const memorizedContext = useMemo(
|
||||
() =>
|
||||
({
|
||||
userEndpoint,
|
||||
tenantEndpoint,
|
||||
}) satisfies AppData,
|
||||
[userEndpoint]
|
||||
[tenantEndpoint]
|
||||
);
|
||||
|
||||
return <AppDataContext.Provider value={memorizedContext}>{children}</AppDataContext.Provider>;
|
||||
|
|
|
@ -102,12 +102,12 @@ export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: S
|
|||
};
|
||||
|
||||
const useApi = (props: Omit<StaticApiProps, 'prefixUrl' | 'resourceIndicator'> = {}) => {
|
||||
const { userEndpoint } = useContext(AppDataContext);
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
const { currentTenantId } = useContext(TenantsContext);
|
||||
|
||||
return useStaticApi({
|
||||
...props,
|
||||
prefixUrl: userEndpoint,
|
||||
prefixUrl: tenantEndpoint,
|
||||
resourceIndicator: getManagementApiResourceIndicator(currentTenantId),
|
||||
});
|
||||
};
|
||||
|
|
|
@ -30,7 +30,7 @@ type Props = {
|
|||
};
|
||||
|
||||
function AdvancedSettings({ applicationType, oidcConfig }: Props) {
|
||||
const { userEndpoint } = useContext(AppDataContext);
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
const {
|
||||
register,
|
||||
formState: { errors },
|
||||
|
@ -55,11 +55,11 @@ function AdvancedSettings({ applicationType, oidcConfig }: Props) {
|
|||
description="application_details.advanced_settings_description"
|
||||
learnMoreLink="https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint"
|
||||
>
|
||||
{userEndpoint && (
|
||||
{tenantEndpoint && (
|
||||
<FormField title="application_details.config_endpoint">
|
||||
<CopyToClipboard
|
||||
className={styles.textField}
|
||||
value={tryApplyCustomDomain(appendPath(userEndpoint, openIdProviderConfigPath).href)}
|
||||
value={tryApplyCustomDomain(appendPath(tenantEndpoint, openIdProviderConfigPath).href)}
|
||||
variant="border"
|
||||
/>
|
||||
</FormField>
|
||||
|
@ -102,13 +102,13 @@ function AdvancedSettings({ applicationType, oidcConfig }: Props) {
|
|||
variant="border"
|
||||
/>
|
||||
</FormField>
|
||||
{customDomain?.status === DomainStatus.Active && userEndpoint && (
|
||||
{customDomain?.status === DomainStatus.Active && tenantEndpoint && (
|
||||
<div className={styles.customEndpointNotes}>
|
||||
<DynamicT
|
||||
forKey="domain.custom_endpoint_note"
|
||||
interpolation={{
|
||||
custom: customDomain.domain,
|
||||
default: new URL(userEndpoint).host,
|
||||
default: new URL(tenantEndpoint).host,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -56,7 +56,7 @@ function Guide({ app, isCompact, onClose }: Props) {
|
|||
const sdks = app && applicationTypeAndSdkTypeMappings[app.type];
|
||||
const [selectedSdk, setSelectedSdk] = useState<Optional<SupportedSdk>>();
|
||||
const [activeStepIndex, setActiveStepIndex] = useState(-1);
|
||||
const { userEndpoint } = useContext(AppDataContext);
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
const { data: customDomain } = useCustomDomain();
|
||||
const isCustomDomainActive = customDomain?.status === DomainStatus.Active;
|
||||
|
||||
|
@ -112,16 +112,16 @@ function Guide({ app, isCompact, onClose }: Props) {
|
|||
}}
|
||||
>
|
||||
<Suspense fallback={<StepsSkeleton />}>
|
||||
{GuideComponent && userEndpoint && (
|
||||
{GuideComponent && tenantEndpoint && (
|
||||
<GuideComponent
|
||||
appId={appId}
|
||||
appSecret={appSecret}
|
||||
endpoint={
|
||||
isCustomDomainActive
|
||||
? applyDomain(userEndpoint.toString(), customDomain.domain)
|
||||
: userEndpoint
|
||||
? applyDomain(tenantEndpoint.toString(), customDomain.domain)
|
||||
: tenantEndpoint
|
||||
}
|
||||
alternativeEndpoint={conditional(isCustomDomainActive && userEndpoint)}
|
||||
alternativeEndpoint={conditional(isCustomDomainActive && tenantEndpoint)}
|
||||
redirectUris={oidcClientMetadata.redirectUris}
|
||||
postLogoutRedirectUris={oidcClientMetadata.postLogoutRedirectUris}
|
||||
activeStepIndex={activeStepIndex}
|
||||
|
|
|
@ -40,7 +40,7 @@ type GetStartedMetadata = {
|
|||
|
||||
const useGetStartedMetadata = () => {
|
||||
const { configs, updateConfigs } = useConfigs();
|
||||
const { userEndpoint } = useContext(AppDataContext);
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
const theme = useTheme();
|
||||
const isLightMode = theme === Theme.Light;
|
||||
const { navigate } = useTenantPathname();
|
||||
|
@ -58,7 +58,7 @@ const useGetStartedMetadata = () => {
|
|||
isComplete: configs?.livePreviewChecked,
|
||||
onClick: async () => {
|
||||
void updateConfigs({ livePreviewChecked: true });
|
||||
window.open(new URL('/demo-app', userEndpoint), '_blank');
|
||||
window.open(new URL('/demo-app', tenantEndpoint), '_blank');
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -103,7 +103,7 @@ const useGetStartedMetadata = () => {
|
|||
isLightMode,
|
||||
navigate,
|
||||
updateConfigs,
|
||||
userEndpoint,
|
||||
tenantEndpoint,
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -8,15 +8,15 @@ import Tag from '@/ds-components/Tag';
|
|||
import * as styles from './index.module.scss';
|
||||
|
||||
function DefaultDomain() {
|
||||
const { userEndpoint } = useContext(AppDataContext);
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
|
||||
if (!userEndpoint) {
|
||||
if (!tenantEndpoint) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<CopyToClipboard className={styles.domain} value={userEndpoint.host} variant="text" />
|
||||
<CopyToClipboard className={styles.domain} value={tenantEndpoint.host} variant="text" />
|
||||
<Tag status="success" type="state" variant="plain">
|
||||
<DynamicT forKey="domain.status.in_used" />
|
||||
</Tag>
|
||||
|
|
Loading…
Reference in a new issue