'use client'; import { useState, type FormEvent } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { appPath } from '@/lib/base-path'; import type { FeishuBinding } from '@/lib/feishu'; export function FeishuAccount({ binding, configured, passwordSet = true }: { binding: FeishuBinding; configured: boolean; passwordSet?: boolean }) { const router = useRouter(); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(''); async function unbind(event: FormEvent) { event.preventDefault(); const form = event.currentTarget; const password = new FormData(form).get('password'); setBusy(true); setError(''); setSuccess(''); try { const response = await fetch(appPath('/api/account/feishu'), { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ password }) }); const data = await response.json(); if (!response.ok) throw new Error(data.error || '解绑失败,请重试。'); form.reset(); setSuccess('已解除飞书绑定,其他设备的登录已失效。'); router.replace('/account/feishu'); router.refresh(); } catch (cause) { setError(cause instanceof Error ? cause.message : '网络异常,请重试。'); } finally { setBusy(false); } } return
{error &&
{error}
} {success &&
{success}
} {binding ? <>

已绑定:{binding.name}

{!passwordSet ? <>

当前账号通过飞书注册,尚未设置系统密码。请先设置密码,再解除绑定。

设置系统密码 : <>

解除绑定需验证系统密码,其他设备需重新登录。解绑后此飞书身份再次登录会创建新账号;原需求仍可通过当前账号密码访问。

} : configured ?
:

飞书登录尚未配置,请联系管理员完成飞书应用设置。

}
; }