mirror of
https://github.com/langgenius/dify.git
synced 2026-08-02 02:40:43 +08:00
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import type { ModelProvider } from '../../declarations'
|
|
import { useMemo } from 'react'
|
|
|
|
export const useCredentialStatus = (provider: ModelProvider | undefined) => {
|
|
const { current_credential_id, current_credential_name, available_credentials } =
|
|
provider?.custom_configuration ?? {}
|
|
const hasCredential = !!available_credentials?.length
|
|
const authRemoved = hasCredential && !current_credential_id && !current_credential_name
|
|
const currentCredential = available_credentials?.find(
|
|
(credential) => credential.credential_id === current_credential_id,
|
|
)
|
|
const notAllowedToUse = currentCredential?.not_allowed_to_use
|
|
const authorized = !!(current_credential_id && current_credential_name && !notAllowedToUse)
|
|
|
|
return useMemo(
|
|
() => ({
|
|
hasCredential,
|
|
authorized,
|
|
authRemoved,
|
|
current_credential_id,
|
|
current_credential_name,
|
|
available_credentials,
|
|
notAllowedToUse,
|
|
}),
|
|
[
|
|
hasCredential,
|
|
authorized,
|
|
authRemoved,
|
|
current_credential_id,
|
|
current_credential_name,
|
|
available_credentials,
|
|
notAllowedToUse,
|
|
],
|
|
)
|
|
}
|