'use client' import type { FC } from 'react' import { Avatar } from '@langgenius/dify-ui/avatar' import { Button } from '@langgenius/dify-ui/button' import { useState } from 'react' import { useTranslation } from 'react-i18next' import { deviceApproveAccount, deviceDenyAccount } from '@/service/device-flow' import { approveErrorCopy } from '../utils/error-copy' type Props = { userCode: string accountEmail?: string accountName?: string accountAvatarUrl?: string | null defaultWorkspace?: string onApproved: () => void onDenied: () => void onError: (message: string) => void } /** * AuthorizeAccount is the account-branch authorize screen. Called with a * live console session already established (user bounced through /signin). * Posts to /openapi/v1/oauth/device/{approve,deny}; these endpoints mint * the dfoa_ token server-side. */ const AuthorizeAccount: FC = ({ userCode, accountEmail, accountName, accountAvatarUrl, defaultWorkspace, onApproved, onDenied, onError, }) => { const { t } = useTranslation('deviceFlow') const [busy, setBusy] = useState(false) const approve = async () => { setBusy(true) try { await deviceApproveAccount(userCode) onApproved() } catch (e) { onError(approveErrorCopy(e, t)) } finally { setBusy(false) } } const deny = async () => { setBusy(true) try { await deviceDenyAccount(userCode) onDenied() } catch (e) { onError(approveErrorCopy(e, t)) } finally { setBusy(false) } } return (

{t(($) => $['authorize.title'])}

{t(($) => $['authorize.accountSubtitle'])}

{accountName &&

{accountName}

} {accountEmail &&

{accountEmail}

}
{defaultWorkspace && (
{t(($) => $['authorize.workspace'])}{' '} {defaultWorkspace}
)}
) } export default AuthorizeAccount