2025-07-17 17:18:44 +08:00
|
|
|
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,
|
2025-08-25 16:12:29 +08:00
|
|
|
notAllowCustomCredential,
|
2025-07-17 17:18:44 +08:00
|
|
|
} = usePluginAuth(pluginPayload, !!pluginPayload.provider)
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={cn(!isAuthorized && className)}>
|
|
|
|
|
{
|
|
|
|
|
!isAuthorized && (
|
|
|
|
|
<Authorize
|
|
|
|
|
pluginPayload={pluginPayload}
|
|
|
|
|
canOAuth={canOAuth}
|
|
|
|
|
canApiKey={canApiKey}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
onUpdate={invalidPluginCredentialInfo}
|
2025-08-25 16:12:29 +08:00
|
|
|
notAllowCustomCredential={notAllowCustomCredential}
|
2025-07-17 17:18:44 +08:00
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
isAuthorized && !children && (
|
|
|
|
|
<Authorized
|
|
|
|
|
pluginPayload={pluginPayload}
|
|
|
|
|
credentials={credentials}
|
|
|
|
|
canOAuth={canOAuth}
|
|
|
|
|
canApiKey={canApiKey}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
onUpdate={invalidPluginCredentialInfo}
|
2025-08-25 16:12:29 +08:00
|
|
|
notAllowCustomCredential={notAllowCustomCredential}
|
2025-07-17 17:18:44 +08:00
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
isAuthorized && children
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default memo(PluginAuth)
|