Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

plugin-auth.tsx 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { memo } from 'react'
  2. import Authorize from './authorize'
  3. import Authorized from './authorized'
  4. import type { PluginPayload } from './types'
  5. import { usePluginAuth } from './hooks/use-plugin-auth'
  6. import cn from '@/utils/classnames'
  7. type PluginAuthProps = {
  8. pluginPayload: PluginPayload
  9. children?: React.ReactNode
  10. className?: string
  11. }
  12. const PluginAuth = ({
  13. pluginPayload,
  14. children,
  15. className,
  16. }: PluginAuthProps) => {
  17. const {
  18. isAuthorized,
  19. canOAuth,
  20. canApiKey,
  21. credentials,
  22. disabled,
  23. invalidPluginCredentialInfo,
  24. notAllowCustomCredential,
  25. } = usePluginAuth(pluginPayload, !!pluginPayload.provider)
  26. return (
  27. <div className={cn(!isAuthorized && className)}>
  28. {
  29. !isAuthorized && (
  30. <Authorize
  31. pluginPayload={pluginPayload}
  32. canOAuth={canOAuth}
  33. canApiKey={canApiKey}
  34. disabled={disabled}
  35. onUpdate={invalidPluginCredentialInfo}
  36. notAllowCustomCredential={notAllowCustomCredential}
  37. />
  38. )
  39. }
  40. {
  41. isAuthorized && !children && (
  42. <Authorized
  43. pluginPayload={pluginPayload}
  44. credentials={credentials}
  45. canOAuth={canOAuth}
  46. canApiKey={canApiKey}
  47. disabled={disabled}
  48. onUpdate={invalidPluginCredentialInfo}
  49. notAllowCustomCredential={notAllowCustomCredential}
  50. />
  51. )
  52. }
  53. {
  54. isAuthorized && children
  55. }
  56. </div>
  57. )
  58. }
  59. export default memo(PluginAuth)