Skip to content

Commit cad19b6

Browse files
Copilothotlong
andcommitted
refactor: address code review feedback
- Add documentation for discovery property access in ObjectStackAdapter - Import and use DiscoveryInfo type in ConditionalAuthWrapper for type safety - Add comment explaining empty baseUrl in ConditionalAuthWrapper Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 5226f7f commit cad19b6

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

apps/console/src/components/ConditionalAuthWrapper.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useState, useEffect, ReactNode } from 'react';
99
import { ObjectStackAdapter } from './dataSource';
1010
import { AuthProvider } from '@object-ui/auth';
1111
import { LoadingScreen } from './components/LoadingScreen';
12+
import type { DiscoveryInfo } from '@object-ui/react';
1213

1314
interface ConditionalAuthWrapperProps {
1415
children: ReactNode;
@@ -35,18 +36,20 @@ export function ConditionalAuthWrapper({ children, authUrl }: ConditionalAuthWra
3536
async function checkAuthStatus() {
3637
try {
3738
// Create a temporary adapter to fetch discovery
39+
// Empty baseUrl allows the adapter to use browser-relative paths
40+
// This works because the console app is served from the same origin as the API
3841
const adapter = new ObjectStackAdapter({
3942
baseUrl: '',
4043
autoReconnect: false,
4144
});
4245

4346
await adapter.connect();
44-
const discovery = await adapter.getDiscovery();
47+
const discovery = await adapter.getDiscovery() as DiscoveryInfo | null;
4548

4649
if (!cancelled) {
4750
// Check if auth is enabled in discovery
4851
// Default to true if discovery doesn't provide this information
49-
const isAuthEnabled = (discovery as any)?.services?.auth?.enabled ?? true;
52+
const isAuthEnabled = discovery?.services?.auth?.enabled ?? true;
5053
setAuthEnabled(isAuthEnabled);
5154
}
5255
} catch (error) {

packages/data-objectstack/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ export class ObjectStackAdapter<T = unknown> implements DataSource<T> {
588588
* Get the discovery information from the connected server.
589589
* Returns the capabilities and service status of the ObjectStack server.
590590
*
591+
* Note: This accesses an internal property of the ObjectStackClient.
592+
* The discovery data is populated during client.connect() and cached.
593+
*
591594
* @returns Promise resolving to discovery data, or null if not connected
592595
*/
593596
async getDiscovery(): Promise<unknown | null> {
@@ -596,7 +599,9 @@ export class ObjectStackAdapter<T = unknown> implements DataSource<T> {
596599
await this.connect();
597600

598601
// Access discovery data from the client
599-
// @ts-expect-error - Accessing internal property
602+
// The ObjectStackClient caches discovery during connect()
603+
// This is an internal property, but documented for this use case
604+
// @ts-expect-error - Accessing internal discovery property
600605
return this.client.discovery || null;
601606
} catch {
602607
return null;

0 commit comments

Comments
 (0)