Skip to content

Commit

Permalink
fix(frontend): Unbreak undiscriminated credentials input
Browse files Browse the repository at this point in the history
- Patch for breakage from #8524
- Resolves #8635
  • Loading branch information
Pwuts committed Nov 13, 2024
1 parent e907ffd commit d2579a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions autogpt_platform/frontend/src/hooks/useCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ export default function useCredentials(): CredentialsData | null {
]) ||
null;

if (!discriminatorValue && credentialsSchema.credentials_provider.length > 1) {
throw new Error("Multi-provider credential input requires discriminator!");
}

const providerName =
discriminatorValue || credentialsSchema.credentials_provider;
discriminatorValue || credentialsSchema.credentials_provider[0];
const provider = allProviders ? allProviders[providerName] : null;

// If block input schema doesn't have credentials, return null
Expand All @@ -60,13 +64,14 @@ export default function useCredentials(): CredentialsData | null {

// No provider means maybe it's still loading
if (!provider) {
return {
provider: credentialsSchema.credentials_provider,
schema: credentialsSchema,
supportsApiKey,
supportsOAuth2,
isLoading: true,
};
// return {
// provider: credentialsSchema.credentials_provider,
// schema: credentialsSchema,
// supportsApiKey,
// supportsOAuth2,
// isLoading: true,
// };
return null;
}

// Filter by OAuth credentials that have sufficient scopes for this block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export type CredentialsProviderName =
(typeof PROVIDER_NAMES)[keyof typeof PROVIDER_NAMES];

export type BlockIOCredentialsSubSchema = BlockIOSubSchemaMeta & {
credentials_provider: CredentialsProviderName;
credentials_provider: CredentialsProviderName[];
credentials_scopes?: string[];
credentials_types: Array<CredentialsType>;
discriminator?: string;
Expand Down

0 comments on commit d2579a6

Please sign in to comment.