mirror of
https://github.com/langgenius/dify.git
synced 2025-07-30 04:45:43 +00:00
26 lines
964 B
TypeScript
26 lines
964 B
TypeScript
![]() |
import { useAppContext } from '@/context/app-context'
|
||
|
import {
|
||
|
useGetPluginCredentialInfoHook,
|
||
|
useInvalidPluginCredentialInfoHook,
|
||
|
} from './use-credential'
|
||
|
import { CredentialTypeEnum } from '../types'
|
||
|
import type { PluginPayload } from '../types'
|
||
|
|
||
|
export const usePluginAuth = (pluginPayload: PluginPayload, enable?: boolean) => {
|
||
|
const { data } = useGetPluginCredentialInfoHook(pluginPayload, enable)
|
||
|
const { isCurrentWorkspaceManager } = useAppContext()
|
||
|
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,
|
||
|
credentials: data?.credentials || [],
|
||
|
disabled: !isCurrentWorkspaceManager,
|
||
|
invalidPluginCredentialInfo,
|
||
|
}
|
||
|
}
|