b088cb17b8
- ServerConfigsLoader: skip validateAuthMetadata when getAuthMetadata()
rejects (404 on /auth_issuer means server uses traditional SSO, not
native Matrix OIDC/MAS - this is expected and should not log errors)
- Router: use HydrateFallback={() => null} instead of hydrateFallbackElement={null}
so react-router v7 counts it as truthy and suppresses the spurious warning
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { ReactNode, useCallback, useMemo } from 'react';
|
|
import { Capabilities, validateAuthMetadata, ValidatedAuthMetadata } from 'matrix-js-sdk';
|
|
import { AsyncStatus, useAsyncCallbackValue } from '../hooks/useAsyncCallback';
|
|
import { useMatrixClient } from '../hooks/useMatrixClient';
|
|
import { MediaConfig } from '../hooks/useMediaConfig';
|
|
import { promiseFulfilledResult } from '../utils/common';
|
|
|
|
export type ServerConfigs = {
|
|
capabilities?: Capabilities;
|
|
mediaConfig?: MediaConfig;
|
|
authMetadata?: ValidatedAuthMetadata;
|
|
};
|
|
|
|
type ServerConfigsLoaderProps = {
|
|
children: (configs: ServerConfigs) => ReactNode;
|
|
};
|
|
export function ServerConfigsLoader({ children }: ServerConfigsLoaderProps) {
|
|
const mx = useMatrixClient();
|
|
const fallbackConfigs = useMemo(() => ({}), []);
|
|
|
|
const [configsState] = useAsyncCallbackValue<ServerConfigs, unknown>(
|
|
useCallback(async () => {
|
|
const result = await Promise.allSettled([
|
|
mx.getCapabilities(),
|
|
mx.getMediaConfig(),
|
|
mx.getAuthMetadata(),
|
|
]);
|
|
|
|
const capabilities = promiseFulfilledResult(result[0]);
|
|
const mediaConfig = promiseFulfilledResult(result[1]);
|
|
const authMetadata = promiseFulfilledResult(result[2]);
|
|
let validatedAuthMetadata: ValidatedAuthMetadata | undefined;
|
|
|
|
// Only validate if the server returned metadata — a rejected promise means no native
|
|
// Matrix OIDC (MSC3861/MAS), which is normal for servers using traditional SSO.
|
|
if (authMetadata !== undefined) {
|
|
try {
|
|
validatedAuthMetadata = validateAuthMetadata(authMetadata);
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
return {
|
|
capabilities,
|
|
mediaConfig,
|
|
authMetadata: validatedAuthMetadata,
|
|
};
|
|
}, [mx]),
|
|
);
|
|
|
|
const configs: ServerConfigs =
|
|
configsState.status === AsyncStatus.Success ? configsState.data : fallbackConfigs;
|
|
|
|
return children(configs);
|
|
}
|