Skip to content

Commit adee529

Browse files
author
Matthew Valancy
committed
feat: wire frontend OAuth config UI to backend GraphQL API
- Add OAuth config GraphQL queries and mutations to queries.ts: - GET_OAUTH_PROVIDER_CONFIGS - GET_OAUTH_PROVIDER_CONFIG - UPDATE_OAUTH_PROVIDER_CONFIG - DELETE_OAUTH_PROVIDER_CONFIG - Update Admin.tsx OAuthProviderManagement component: - Use useQuery to load OAuth configs on mount - Use useMutation to save configs to backend - Real-time loading states during API calls - Automatic refetch after save - Proper error handling OAuth provider configuration now fully functional end-to-end: Admin UI → GraphQL API → SQLite Storage
1 parent 3a8af45 commit adee529

2 files changed

Lines changed: 92 additions & 12 deletions

File tree

packages/web/src/lib/queries.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,61 @@ export const DELETE_EDGE = gql`
381381
}
382382
`;
383383

384+
// OAuth Provider Configuration Queries
385+
export const GET_OAUTH_PROVIDER_CONFIGS = gql`
386+
query GetOAuthProviderConfigs {
387+
oauthProviderConfigs {
388+
provider
389+
enabled
390+
clientId
391+
clientSecret
392+
callbackUrl
393+
configured
394+
createdAt
395+
updatedAt
396+
}
397+
}
398+
`;
399+
400+
export const GET_OAUTH_PROVIDER_CONFIG = gql`
401+
query GetOAuthProviderConfig($provider: String!) {
402+
oauthProviderConfig(provider: $provider) {
403+
provider
404+
enabled
405+
clientId
406+
clientSecret
407+
callbackUrl
408+
configured
409+
createdAt
410+
updatedAt
411+
}
412+
}
413+
`;
414+
415+
export const UPDATE_OAUTH_PROVIDER_CONFIG = gql`
416+
mutation UpdateOAuthProviderConfig($input: OAuthProviderConfigInput!) {
417+
updateOAuthProviderConfig(input: $input) {
418+
provider
419+
enabled
420+
clientId
421+
clientSecret
422+
callbackUrl
423+
configured
424+
createdAt
425+
updatedAt
426+
}
427+
}
428+
`;
429+
430+
export const DELETE_OAUTH_PROVIDER_CONFIG = gql`
431+
mutation DeleteOAuthProviderConfig($provider: String!) {
432+
deleteOAuthProviderConfig(provider: $provider) {
433+
success
434+
message
435+
}
436+
}
437+
`;
438+
384439
// Backward compatibility exports
385440
export const GET_NODES = GET_WORK_ITEMS;
386441
export const GET_NODE_BY_ID = GET_WORK_ITEM_BY_ID;

packages/web/src/pages/Admin.tsx

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { AdminUserManagement } from '../components/AdminUserManagement';
55
import { CustomDropdown } from '../components/CustomDropdown';
66
import { APP_VERSION } from '../utils/version';
77
import { useSystemConfig } from '../hooks/useSystemConfig';
8+
import { useQuery, useMutation } from '@apollo/client';
9+
import { GET_OAUTH_PROVIDER_CONFIGS, UPDATE_OAUTH_PROVIDER_CONFIG } from '../lib/queries';
810

911
export function Admin() {
1012
const { currentUser } = useAuth();
@@ -298,28 +300,51 @@ function OAuthProviderManagement() {
298300
});
299301

300302
const [saved, setSaved] = useState(false);
301-
const [loading, setLoading] = useState(false);
303+
304+
const { data, loading: queryLoading, refetch } = useQuery(GET_OAUTH_PROVIDER_CONFIGS);
305+
const [updateOAuthConfig, { loading: mutationLoading }] = useMutation(UPDATE_OAUTH_PROVIDER_CONFIG);
306+
307+
const loading = queryLoading || mutationLoading;
302308

303309
useEffect(() => {
304-
// TODO: Load OAuth provider configuration from backend
305-
console.log('Loading OAuth provider configuration...');
306-
}, []);
310+
if (data?.oauthProviderConfigs) {
311+
const loadedProviders = { ...providers };
312+
data.oauthProviderConfigs.forEach((config: any) => {
313+
if (loadedProviders[config.provider as keyof typeof loadedProviders]) {
314+
loadedProviders[config.provider as keyof typeof loadedProviders] = {
315+
enabled: config.enabled,
316+
clientId: config.clientId || '',
317+
clientSecret: config.clientSecret || '',
318+
callbackUrl: config.callbackUrl,
319+
configured: config.configured,
320+
};
321+
}
322+
});
323+
setProviders(loadedProviders);
324+
}
325+
}, [data]);
307326

308327
const handleSave = async () => {
309-
setLoading(true);
310328
try {
311-
// TODO: Save OAuth provider configuration to backend
312-
console.log('Saving OAuth provider configuration:', providers);
313-
314-
// Simulate API call
315-
await new Promise(resolve => setTimeout(resolve, 1000));
329+
for (const [providerKey, config] of Object.entries(providers)) {
330+
await updateOAuthConfig({
331+
variables: {
332+
input: {
333+
provider: providerKey,
334+
enabled: config.enabled,
335+
clientId: config.clientId,
336+
clientSecret: config.clientSecret,
337+
callbackUrl: config.callbackUrl,
338+
},
339+
},
340+
});
341+
}
316342

343+
await refetch();
317344
setSaved(true);
318345
setTimeout(() => setSaved(false), 3000);
319346
} catch (error) {
320347
console.error('Failed to save OAuth configuration:', error);
321-
} finally {
322-
setLoading(false);
323348
}
324349
};
325350

0 commit comments

Comments
 (0)