mirror of
https://github.com/langgenius/dify.git
synced 2025-07-30 13:00:14 +00:00
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
![]() |
import { memo } from 'react'
|
||
|
import Authorize from './authorize'
|
||
|
import Authorized from './authorized'
|
||
|
import type { PluginPayload } from './types'
|
||
|
import { usePluginAuth } from './hooks/use-plugin-auth'
|
||
|
import cn from '@/utils/classnames'
|
||
|
|
||
|
type PluginAuthProps = {
|
||
|
pluginPayload: PluginPayload
|
||
|
children?: React.ReactNode
|
||
|
className?: string
|
||
|
}
|
||
|
const PluginAuth = ({
|
||
|
pluginPayload,
|
||
|
children,
|
||
|
className,
|
||
|
}: PluginAuthProps) => {
|
||
|
const {
|
||
|
isAuthorized,
|
||
|
canOAuth,
|
||
|
canApiKey,
|
||
|
credentials,
|
||
|
disabled,
|
||
|
invalidPluginCredentialInfo,
|
||
|
} = usePluginAuth(pluginPayload, !!pluginPayload.provider)
|
||
|
|
||
|
return (
|
||
|
<div className={cn(!isAuthorized && className)}>
|
||
|
{
|
||
|
!isAuthorized && (
|
||
|
<Authorize
|
||
|
pluginPayload={pluginPayload}
|
||
|
canOAuth={canOAuth}
|
||
|
canApiKey={canApiKey}
|
||
|
disabled={disabled}
|
||
|
onUpdate={invalidPluginCredentialInfo}
|
||
|
/>
|
||
|
)
|
||
|
}
|
||
|
{
|
||
|
isAuthorized && !children && (
|
||
|
<Authorized
|
||
|
pluginPayload={pluginPayload}
|
||
|
credentials={credentials}
|
||
|
canOAuth={canOAuth}
|
||
|
canApiKey={canApiKey}
|
||
|
disabled={disabled}
|
||
|
onUpdate={invalidPluginCredentialInfo}
|
||
|
/>
|
||
|
)
|
||
|
}
|
||
|
{
|
||
|
isAuthorized && children
|
||
|
}
|
||
|
</div>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
export default memo(PluginAuth)
|