dify/web/app/components/plugins/plugin-auth/hooks/use-plugin-auth.ts
Joel 1a2ba2237d
chore: new agent enchance (#39040)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-16 06:46:41 +00:00

33 lines
985 B
TypeScript

import type { PluginPayload } from '../types'
import { CredentialTypeEnum } from '../types'
import {
useGetPluginCredentialInfoHook,
useInvalidPluginCredentialInfoHook,
} from './use-credential'
export const usePluginAuth = (
pluginPayload: PluginPayload,
enable?: boolean,
includeCredentialIds?: string[],
) => {
const { data, isLoading } = useGetPluginCredentialInfoHook(
pluginPayload,
enable,
includeCredentialIds,
)
const isAuthorized = !!data?.credentials.length
const canOAuth = data?.supported_credential_types.includes(CredentialTypeEnum.OAUTH2)
const canApiKey = data?.supported_credential_types.includes(CredentialTypeEnum.API_KEY)
const invalidPluginCredentialInfo = useInvalidPluginCredentialInfoHook(pluginPayload)
return {
isAuthorized,
canOAuth,
canApiKey,
isLoading,
credentials: data?.credentials || [],
notAllowCustomCredential: data?.allow_custom_token === false,
invalidPluginCredentialInfo,
}
}