Skip to content

Commit 787d192

Browse files
committed
Fix no auth issue in ui component
1 parent bc232fd commit 787d192

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

ee/ui-component/components/MorphikUI.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const MorphikUI: React.FC<MorphikUIProps> = ({
153153
{activeSection === "connections" && (
154154
<div className="h-full overflow-auto p-4 md:p-6">
155155
{/* Wrapper div for consistent padding and full height */}
156-
<ConnectorList apiBaseUrl={effectiveApiBaseUrl} />
156+
<ConnectorList apiBaseUrl={effectiveApiBaseUrl} authToken={authToken} />
157157
</div>
158158
)}
159159
</main>

ee/ui-component/components/connectors/ConnectorCard.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ interface ConnectorCardProps {
2020
displayName: string;
2121
icon?: React.ElementType;
2222
apiBaseUrl: string;
23+
authToken: string | null;
2324
}
2425

25-
export function ConnectorCard({ connectorType, displayName, icon: ConnectorIcon, apiBaseUrl }: ConnectorCardProps) {
26+
export function ConnectorCard({
27+
connectorType,
28+
displayName,
29+
icon: ConnectorIcon,
30+
apiBaseUrl,
31+
authToken,
32+
}: ConnectorCardProps) {
2633
const [authStatus, setAuthStatus] = useState<ConnectorAuthStatus | null>(null);
2734
const [isLoading, setIsLoading] = useState<boolean>(true);
2835
const [error, setError] = useState<string | null>(null);
@@ -40,15 +47,15 @@ export function ConnectorCard({ connectorType, displayName, icon: ConnectorIcon,
4047
setIsLoading(true);
4148
setError(null);
4249
try {
43-
const status = await getConnectorAuthStatus(apiBaseUrl, connectorType);
50+
const status = await getConnectorAuthStatus(apiBaseUrl, connectorType, authToken);
4451
setAuthStatus(status);
4552
} catch (err) {
4653
setError(err instanceof Error ? err.message : "An unknown error occurred while fetching status.");
4754
setAuthStatus(null);
4855
} finally {
4956
setIsLoading(false);
5057
}
51-
}, [apiBaseUrl, connectorType]);
58+
}, [apiBaseUrl, connectorType, authToken]);
5259

5360
useEffect(() => {
5461
fetchStatus();
@@ -73,7 +80,7 @@ export function ConnectorCard({ connectorType, displayName, icon: ConnectorIcon,
7380
setError(null);
7481
setIsSubmitting(true);
7582
try {
76-
await disconnectConnector(apiBaseUrl, connectorType);
83+
await disconnectConnector(apiBaseUrl, connectorType, authToken);
7784
await fetchStatus();
7885
} catch (err) {
7986
setError(err instanceof Error ? err.message : "Failed to disconnect.");
@@ -102,7 +109,7 @@ export function ConnectorCard({ connectorType, displayName, icon: ConnectorIcon,
102109
try {
103110
// Pass metadata and rules to ingestConnectorFile
104111
// Note: ingestConnectorFile in lib/connectorsApi.ts will need to be updated to accept these
105-
const result = await ingestConnectorFile(apiBaseUrl, connectorType, ingestionTargetFileId, {
112+
const result = await ingestConnectorFile(apiBaseUrl, connectorType, authToken, ingestionTargetFileId, {
106113
metadata: JSON.parse(ingestionMetadata),
107114
rules: JSON.parse(ingestionRules),
108115
// morphikFolderName and morphikEndUserId can be added here if there are UI elements to collect them
@@ -222,7 +229,12 @@ export function ConnectorCard({ connectorType, displayName, icon: ConnectorIcon,
222229
<DialogTitle>Browse Files: {displayName}</DialogTitle>
223230
</DialogHeader>
224231
<div className="flex-grow overflow-auto py-4">
225-
<FileBrowser connectorType={connectorType} apiBaseUrl={apiBaseUrl} onFileIngest={handleFileIngest} />
232+
<FileBrowser
233+
connectorType={connectorType}
234+
apiBaseUrl={apiBaseUrl}
235+
authToken={authToken}
236+
onFileIngest={handleFileIngest}
237+
/>
226238
</div>
227239
<DialogFooter className="mt-auto">
228240
<DialogClose asChild>

ee/ui-component/components/connectors/ConnectorList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ const availableConnectors = [
2222

2323
interface ConnectorListProps {
2424
apiBaseUrl: string; // Added apiBaseUrl prop
25+
authToken: string | null;
2526
}
2627

27-
export function ConnectorList({ apiBaseUrl }: ConnectorListProps) {
28+
export function ConnectorList({ apiBaseUrl, authToken }: ConnectorListProps) {
2829
if (availableConnectors.length === 0) {
2930
return (
3031
<div className="text-center text-muted-foreground">
@@ -42,6 +43,7 @@ export function ConnectorList({ apiBaseUrl }: ConnectorListProps) {
4243
displayName={connector.displayName}
4344
icon={connector.icon}
4445
apiBaseUrl={apiBaseUrl} // Pass apiBaseUrl down
46+
authToken={authToken} // Pass authToken down
4547
/>
4648
))}
4749
</div>

ee/ui-component/components/connectors/FileBrowser.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const DEFAULT_PAGE_SIZE = 20;
2424
interface FileBrowserProps {
2525
connectorType: string;
2626
apiBaseUrl: string;
27+
authToken: string | null;
2728
onFileIngest: (fileId: string, fileName: string, connectorType: string) => void; // Added connectorType
2829
initialPath?: string | null; // Allow null for root
2930
// onPathChange?: (newPath: string | null, newPathName: string | null) => void; // Optional: if parent needs to know
@@ -37,6 +38,7 @@ interface PathCrumb {
3738
export function FileBrowser({
3839
connectorType,
3940
apiBaseUrl,
41+
authToken,
4042
onFileIngest,
4143
initialPath = null, // Default to null for root
4244
}: FileBrowserProps) {
@@ -60,6 +62,7 @@ export function FileBrowser({
6062
const result = await listConnectorFiles(
6163
apiBaseUrl,
6264
connectorType,
65+
authToken,
6366
pathId, // API function handles 'root' case if pathId is 'root' or null
6467
pageToken,
6568
undefined,
@@ -75,7 +78,7 @@ export function FileBrowser({
7578
setIsLoading(false);
7679
}
7780
},
78-
[apiBaseUrl, connectorType]
81+
[apiBaseUrl, connectorType, authToken]
7982
);
8083

8184
useEffect(() => {

ee/ui-component/lib/connectorsApi.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ export interface ConnectorAuthStatus {
66
}
77

88
// Fetches the authentication status for a given connector type
9-
export async function getConnectorAuthStatus(apiBaseUrl: string, connectorType: string): Promise<ConnectorAuthStatus> {
10-
const response = await fetch(`${apiBaseUrl}/ee/connectors/${connectorType}/auth_status`);
9+
export async function getConnectorAuthStatus(
10+
apiBaseUrl: string,
11+
connectorType: string,
12+
authToken: string | null
13+
): Promise<ConnectorAuthStatus> {
14+
const response = await fetch(`${apiBaseUrl}/ee/connectors/${connectorType}/auth_status`, {
15+
headers: {
16+
...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
17+
},
18+
});
1119
if (!response.ok) {
1220
const errorData = await response.json().catch(() => ({}));
1321
throw new Error(
@@ -19,7 +27,14 @@ export async function getConnectorAuthStatus(apiBaseUrl: string, connectorType:
1927

2028
// Initiates the authentication process by redirecting the user
2129
// The backend will handle the actual redirect to the OAuth provider
22-
export function initiateConnectorAuth(apiBaseUrl: string, connectorType: string, appRedirectUri: string): void {
30+
export function initiateConnectorAuth(
31+
apiBaseUrl: string,
32+
connectorType: string,
33+
appRedirectUri: string
34+
// authToken is not typically needed for the initiation step if it's a redirect-based flow
35+
// and the backend establishes session/cookie upon callback.
36+
// If token IS needed by this specific /initiate endpoint, it would be added here.
37+
): void {
2338
// The backend /auth/initiate endpoint itself performs a redirect.
2439
// So, navigating to it will trigger the OAuth flow.
2540
// We add the app_redirect_uri for the backend to use after successful callback.
@@ -29,11 +44,16 @@ export function initiateConnectorAuth(apiBaseUrl: string, connectorType: string,
2944
}
3045

3146
// Disconnects a connector for the current user
32-
export async function disconnectConnector(apiBaseUrl: string, connectorType: string): Promise<void> {
47+
export async function disconnectConnector(
48+
apiBaseUrl: string,
49+
connectorType: string,
50+
authToken: string | null
51+
): Promise<void> {
3352
const response = await fetch(`${apiBaseUrl}/ee/connectors/${connectorType}/disconnect`, {
3453
method: "POST",
3554
headers: {
3655
"Content-Type": "application/json",
56+
...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
3757
},
3858
});
3959
if (!response.ok) {
@@ -59,6 +79,7 @@ export interface ConnectorFile {
5979
export async function listConnectorFiles(
6080
apiBaseUrl: string,
6181
connectorType: string,
82+
authToken: string | null,
6283
path: string | null,
6384
pageToken?: string,
6485
q_filter?: string,
@@ -81,7 +102,7 @@ export async function listConnectorFiles(
81102
method: "GET",
82103
headers: {
83104
"Content-Type": "application/json",
84-
// TODO: Add authorization headers if required by your API setup
105+
...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
85106
},
86107
});
87108

@@ -103,6 +124,7 @@ interface IngestionOptions {
103124
export async function ingestConnectorFile(
104125
apiBaseUrl: string,
105126
connectorType: string,
127+
authToken: string | null,
106128
fileId: string,
107129
// Replace displayName with ingestionOptions
108130
options?: IngestionOptions
@@ -121,7 +143,7 @@ export async function ingestConnectorFile(
121143
method: "POST",
122144
headers: {
123145
"Content-Type": "application/json",
124-
// TODO: Add authorization headers if required
146+
...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
125147
},
126148
body: JSON.stringify(body),
127149
});

ee/ui-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@morphik/ui",
3-
"version": "0.2.9",
3+
"version": "0.2.10",
44
"private": true,
55
"description": "Modern UI component for Morphik - A powerful document processing and querying system",
66
"author": "Morphik Team",

0 commit comments

Comments
 (0)